@ohkit/draggable-box 0.0.1 → 0.0.2
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/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +3 -11
- package/dist/types/utils.d.ts +19 -4
- package/package.json +2 -2
- package/src/index.tsx +80 -95
- package/src/utils.ts +54 -23
package/dist/index.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"react";import{prefixClassname as e,classNames as r}from"@ohkit/prefix-classname";import{findParent as o,addEventListener as i,addClass as a}from"@ohkit/dom-helper";function s(){return s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var o in r)({}).hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},s.apply(null,arguments)}function n(t,e){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},n(t,e)}function d(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}var l=["top-left","top-right","bottom-left","bottom-right"],g=e("ohkit-draggable-box__"),p=/*#__PURE__*/function(e){function p(t){var r;(r=e.call(this,t)||this).draggerRef=null,r.isDragging=!1,r.axisX=void 0,r.axisY=void 0,r.dX=0,r.dY=0,r.startTop=0,r.startLeft=0,r.cachedScaleX=1,r.cachedScaleY=1,r.__moveDisposer=void 0,r.__clickDisposer=void 0,r.__bodyClassDisposer=void 0,r.__upDisposer=void 0,r.__resizeDisposer=void 0,r.dragAreaRef=null,r.enableDrag=function(){r.reportStartPosition(),null==r.__moveDisposer||r.__moveDisposer(),r.__moveDisposer=i(document,"mousemove",function(t){r.__clickDisposer||Math.sqrt(Math.pow(r.dX,2)+Math.pow(r.dY,2))>5&&(r.__clickDisposer=i(document,"click",function(t){t.stopPropagation()},!0),r.__bodyClassDisposer=a([document.body,r.draggerRef],g("moving"))||void 0,r.props.showDragArea&&r.dragAreaRef&&r.showDragArea()),r.dragging(t)},!0),null==r.__upDisposer||r.__upDisposer(),r.__upDisposer=i(document,"mouseup",function(t){r.endDrag(),t.stopPropagation(),t.preventDefault()},!0)},r.startDrag=function(t){2!==t.nativeEvent.button&&(r.axisX=t.nativeEvent.pageX,r.axisY=t.nativeEvent.pageY,r.props.disabled||r.enableDrag())},r.dragging=function(t){r.isDragging=!0;var e=r.props.lockAxis,o=r.dragPositionBoundaries,i=o.minX,a=o.maxX,s=o.minY,n=o.maxY,d=r.cachedScaleY;r.dX=(t.pageX-(r.axisX||0))/r.cachedScaleX,r.dY=(t.pageY-(r.axisY||0))/d;var l=r.dX,g=r.dY;"x"===e?g=0:"y"===e&&(l=0);var p=r.startLeft+l,h=r.startTop+g;"y"!==e&&(p<i?l=i-r.startLeft:p>a&&(l=a-r.startLeft)),"x"!==e&&(h<s?g=s-r.startTop:h>n&&(g=n-r.startTop)),r.draggerRef&&(r.draggerRef.style.transform="translate("+l+"px, "+g+"px)"),t.stopPropagation()},r.endDrag=function(){r.isDragging&&(r.calcPosition(),r.draggerRef&&(r.draggerRef.style.transform=""),r.props.showDragArea&&r.hideDragArea()),null==r.__moveDisposer||r.__moveDisposer(),r.__moveDisposer=void 0,r.__clickDisposer&&requestAnimationFrame(function(){r.__clickDisposer&&(r.__clickDisposer(),r.__clickDisposer=void 0)}),null==r.__upDisposer||r.__upDisposer(),r.__upDisposer=void 0,null==r.__bodyClassDisposer||r.__bodyClassDisposer(),r.__bodyClassDisposer=void 0,r.isDragging=!1},r.showDragArea=function(){if(r.props.showDragArea&&r.dragAreaRef){var t=r.props.lockAxis,e=r.dragPositionBoundaries,o=e.minX,i=e.maxX,a=e.minY,s=e.maxY,n=r.dragBoxSize;r.dragAreaRef.style.border="1px dashed var(--ohkit-color-primary, #1890ff)",r.dragAreaRef.style.backgroundColor="rgba(173, 216, 230, 0.2)","x"===t?(r.dragAreaRef.style.width=i-o+n.width+"px",r.dragAreaRef.style.height="2px",r.dragAreaRef.style.left=o+"px",r.dragAreaRef.style.top=r.startTop+n.height/2+"px",r.dragAreaRef.style.border="none",r.dragAreaRef.style.backgroundColor="transparent",r.dragAreaRef.style.backgroundImage="linear-gradient(to right, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)",r.dragAreaRef.style.backgroundSize="4px 2px"):"y"===t?(r.dragAreaRef.style.width="2px",r.dragAreaRef.style.height=s-a+n.height+"px",r.dragAreaRef.style.left=r.startLeft+n.width/2+"px",r.dragAreaRef.style.top=a+"px",r.dragAreaRef.style.border="none",r.dragAreaRef.style.backgroundColor="transparent",r.dragAreaRef.style.backgroundImage="linear-gradient(to bottom, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)",r.dragAreaRef.style.backgroundSize="2px 4px"):(r.dragAreaRef.style.width=i-o+n.width+"px",r.dragAreaRef.style.height=s-a+n.height+"px",r.dragAreaRef.style.left=o+"px",r.dragAreaRef.style.top=a+"px"),r.dragAreaRef.style.display="block"}},r.hideDragArea=function(){r.dragAreaRef&&(r.dragAreaRef.style.display="none")},r.calcPosition=function(){var t=r.props.lockAxis,e=r.dragPositionBoundaries,o=e.minX,i=e.maxX,a=e.maxY,s=r.windowSize,n=r.startTop,d=r.startLeft;"y"!==t&&(d+=r.dX),"x"!==t&&(n+=r.dY);var l=Math.min(Math.max(e.minY,n),a),g=Math.min(Math.max(o,d),i),p=s.height-l-r.dragBoxSize.height,h=s.width-g-r.dragBoxSize.width;l===r.state.top&&g===r.state.left&&r.state.bottom===p&&r.state.right===h||r.setState({top:l,left:g,bottom:p,right:h}),r.startTop=l,r.startLeft=g,r.dX=r.dY=0};var o=t.placement,s=t.offsetY,n=void 0===s?20:s,d=t.offsetX,l=void 0===d?20:d,p=(void 0===o?"bottom-right":o).split("-"),h=p[0],c=p[1];return r.state={top:"top"===h?n:void 0,bottom:"bottom"===h?n:void 0,left:"left"===c?l:void 0,right:"right"===c?l:void 0},r}var h,c;c=e,(h=p).prototype=Object.create(c.prototype),h.prototype.constructor=h,n(h,c);var f,u,m=p.prototype;return m.getOtherYKey=function(t){return"top"===t?"bottom":"top"},m.getOtherXKey=function(t){return"left"===t?"right":"left"},m.updatePosition=function(t,e){var r,o=this.getOtherYKey(t),i=this.getOtherXKey(e);this.setState(((r={})[o]=this.dragPositionRang.height-(this.state[t]||0),r[i]=this.dragPositionRang.width-(this.state[e]||0),r))},m.getContainer=function(){var t,e=this.props.positionMode;return"fixed"===(void 0===e?"fixed":e)?(t=this.draggerRef)&&o(t,function(t){var e=window.getComputedStyle(t),r=e.getPropertyValue("transform"),o=e.getPropertyValue("filter"),i=e.getPropertyValue("perspective");if("none"!==r||"none"!==o||"none"!==i)return!0},{excludeOwn:!0})||document.documentElement:function(t){return t&&o(t,function(t){if("static"!==window.getComputedStyle(t).getPropertyValue("position"))return!0},{excludeOwn:!0})||document.body}(this.draggerRef)},m.getContainerRect=function(){var t=this.props.positionMode,e="fixed"===(void 0===t?"fixed":t),r=this.getContainer(),o=r.getBoundingClientRect(),i=window.document.scrollingElement||window.document.body,a=r===window.document.body||r===window.document.documentElement;return{width:o.width,height:o.height,left:e&&a?Math.max(o.left,0):o.left+i.scrollLeft,top:e&&a?Math.max(o.top,0):o.top+i.scrollTop,scrollLeft:e&&a?0:r.scrollLeft,scrollTop:e&&a?0:r.scrollTop,scrollerScrollLeft:e&&a?0:i.scrollLeft,scrollerScrollTop:e&&a?0:i.scrollTop}},m.reportStartPosition=function(){if(this.draggerRef){var t=this.draggerRef.getBoundingClientRect(),e=t.top,r=t.left,o=this.getContainerRect(),i=function(t){if(!t)return{scaleX:1,scaleY:1};var e=t.getBoundingClientRect();return{scaleX:t.offsetWidth>0?Math.round(e.width/t.offsetWidth*10)/10:1,scaleY:t.offsetHeight>0?Math.round(e.height/t.offsetHeight*10)/10:1}}(this.draggerRef),a=i.scaleX,s=i.scaleY;this.cachedScaleX=a,this.cachedScaleY=s,this.startTop=(e-o.top+o.scrollerScrollTop)/s+o.scrollTop,this.startLeft=(r-o.left+o.scrollerScrollLeft)/a+o.scrollLeft}},m.componentDidMount=function(){var t=this;this.reportStartPosition(),this.calcPosition(),this.__resizeDisposer=i(window,"resize",function(){t.calcPosition()})},m.componentWillUnmount=function(){var t,e,r,o,i;null==(t=this.__resizeDisposer)||t.call(this),null==(e=this.__bodyClassDisposer)||e.call(this),null==(r=this.__moveDisposer)||r.call(this),null==(o=this.__clickDisposer)||o.call(this),null==(i=this.__upDisposer)||i.call(this)},m.render=function(){var e=this,o=this.props,i=o.className,a=o.zIndex,n=o.children,d=o.showDragArea,l=o.positionMode,p=void 0===l?"fixed":l,h=this.startDrag,c=this.endDrag,f=s({zIndex:a},this.position,{position:p});/*#__PURE__*/return t.createElement(Fragment,null,d&&/*#__PURE__*/t.createElement("div",{className:g("drag-area"),ref:function(t){e.dragAreaRef=t},style:{display:"none",position:p,backgroundColor:"rgba(173, 216, 230, 0.2)",border:"1px dashed var(--ohkit-color-primary, #1890ff)",pointerEvents:"none",zIndex:(a||9999)-1,boxSizing:"border-box",borderRadius:"none"!==this.props.lockAxis?"2px":"0"}}),/*#__PURE__*/t.createElement("div",{className:r(g("container"),i),style:f,ref:function(t){e.draggerRef=t},onMouseDown:h,onMouseUp:c},n))},f=p,(u=[{key:"windowSize",get:function(){var t=this.getContainer();return{height:t.clientHeight,width:t.clientWidth}}},{key:"dragBoxSize",get:function(){var t=0,e=0;return this.draggerRef&&(t=this.draggerRef.offsetWidth,e=this.draggerRef.offsetHeight),{height:e,width:t}}},{key:"dragPositionBoundaries",get:function(){var t=this.props,e=t.boundsX,r=t.boundsY,o=t.placement,i=this.dragBoxSize,a=this.windowSize,s=(void 0===o?"bottom-right":o).split("-"),n=s[0],d=0,l=a.width-i.width,g=0,p=a.height-i.height;if(e){var h=e[0],c=e[1];if("left"===s[1])void 0!==h&&(d=Math.max(d,h)),void 0!==c&&(l=Math.min(l,c));else if(void 0!==h&&void 0!==c?(d=Math.max(d,a.width-c-i.width),l=Math.min(l,a.width-h-i.width)):void 0!==h?l=Math.min(l,a.width-h-i.width):void 0!==c&&(d=Math.max(d,a.width-c-i.width)),d>l){var f=[l,d];d=f[0],l=f[1]}}if(r){var u=r[0],m=r[1];if("top"===n)void 0!==u&&(g=Math.max(g,u)),void 0!==m&&(p=Math.min(p,m));else if(void 0!==u&&void 0!==m?(g=Math.max(g,a.height-m-i.height),p=Math.min(p,a.height-u-i.height)):void 0!==u?p=Math.min(p,a.height-u-i.height):void 0!==m&&(g=Math.max(g,a.height-m-i.height)),g>p){var v=[p,g];g=v[0],p=v[1]}}return{minX:d,maxX:l,minY:g,maxY:p}}},{key:"dragPositionRang",get:function(){var t=this.dragPositionBoundaries;return{width:t.maxX,height:t.maxY}}},{key:"curPositionKey",get:function(){var t=this.props.placement;return t&&l.includes(t)||(t="bottom-right"),t.split("-")}},{key:"position",get:function(){var t=this.curPositionKey,e=t[0],r=t[1],o={};return void 0!==this.state[e]&&(o[e]=this.state[e]+"px"),void 0!==this.state[r]&&(o[r]=this.state[r]+"px"),o}}])&&function(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,d(o.key),o)}}(f.prototype,u),Object.defineProperty(f,"prototype",{writable:!1}),f}(t.Component);p.defaultProps={zIndex:9999,offsetX:20,offsetY:20,placement:"bottom-right",disabled:!1,lockAxis:"none",showDragArea:!1,positionMode:"fixed"};export{p as DraggableBox,g as c,p as default};
|
|
1
|
+
import t from"react";import{prefixClassname as e,classNames as r}from"@ohkit/prefix-classname";import{findParent as i,addEventListener as o,addClass as a}from"@ohkit/dom-helper";function s(){return s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)({}).hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},s.apply(null,arguments)}function n(t,e){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},n(t,e)}function d(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function l(t,e){var r=window.getComputedStyle(t),i=r.getPropertyValue("position"),o=r.getPropertyValue("transform"),a=r.getPropertyValue("filter"),s=r.getPropertyValue("perspective"),n=r.getPropertyValue("contain"),d=r.getPropertyValue("will-change");return e&&"static"!==i||"none"!==o||"none"!==a||"none"!==s||n.includes("paint")||n.includes("layout")||n.includes("strict")||d.includes("transform")||d.includes("perspective")||d.includes("filter")}function p(t,e,r){return Math.min(Math.max(t,e),r)}var h=["top-left","top-right","bottom-left","bottom-right"],c=e("ohkit-draggable-box__"),g=/*#__PURE__*/function(e){function g(t){var r;(r=e.call(this,t)||this).prePositionMode=void 0,r.preDraggerRef=null,r.container=null,r.draggerRef=null,r.isDragging=!1,r.axisX=void 0,r.axisY=void 0,r.dX=0,r.dY=0,r.startTop=0,r.startLeft=0,r.cachedScaleX=1,r.cachedScaleY=1,r.__moveDisposer=void 0,r.__clickDisposer=void 0,r.__bodyClassDisposer=void 0,r.__upDisposer=void 0,r.__resizeDisposer=void 0,r.dragAreaRef=null,r.enableDrag=function(){r.reportStartPosition(),null==r.__moveDisposer||r.__moveDisposer(),r.__moveDisposer=o(document,"mousemove",function(t){r.__clickDisposer||Math.sqrt(Math.pow(r.dX,2)+Math.pow(r.dY,2))>5&&(r.__clickDisposer=o(document,"click",function(t){t.stopPropagation()},!0),r.__bodyClassDisposer=a([document.body,r.draggerRef],c("moving"))||void 0,r.props.showDragArea&&r.dragAreaRef&&r.showDragArea()),r.dragging(t)},!0),null==r.__upDisposer||r.__upDisposer(),r.__upDisposer=o(document,"mouseup",function(t){r.endDrag(),t.stopPropagation(),t.preventDefault()},!0)},r.startDrag=function(t){2!==t.nativeEvent.button&&(r.axisX=t.nativeEvent.pageX,r.axisY=t.nativeEvent.pageY,r.props.disabled||r.enableDrag())},r.dragging=function(t){r.isDragging=!0;var e=r.props.lockAxis,i=r.dragPositionBoundaries,o=i.minX,a=i.maxX,s=i.minY,n=i.maxY,d=r.cachedScaleY;r.dX=(t.pageX-(r.axisX||0))/r.cachedScaleX,r.dY=(t.pageY-(r.axisY||0))/d;var l=r.dX,p=r.dY;"x"===e?p=0:"y"===e&&(l=0);var h=r.startLeft+l,c=r.startTop+p;"y"!==e&&(h<o?l=o-r.startLeft:h>a&&(l=a-r.startLeft)),"x"!==e&&(c<s?p=s-r.startTop:c>n&&(p=n-r.startTop)),r.draggerRef&&(r.draggerRef.style.transform="translate("+l+"px, "+p+"px)"),t.stopPropagation()},r.endDrag=function(){r.isDragging&&(r.calcPosition(),r.draggerRef&&(r.draggerRef.style.transform=""),r.props.showDragArea&&r.hideDragArea()),null==r.__moveDisposer||r.__moveDisposer(),r.__moveDisposer=void 0,r.__clickDisposer&&requestAnimationFrame(function(){r.__clickDisposer&&(r.__clickDisposer(),r.__clickDisposer=void 0)}),null==r.__upDisposer||r.__upDisposer(),r.__upDisposer=void 0,null==r.__bodyClassDisposer||r.__bodyClassDisposer(),r.__bodyClassDisposer=void 0,r.isDragging=!1},r.showDragArea=function(){if(r.props.showDragArea&&r.dragAreaRef){var t=r.props.lockAxis,e=r.dragPositionBoundaries,i=e.minX,o=e.maxX,a=e.minY,s=e.maxY,n=r.dragBoxSize;r.dragAreaRef.style.border="1px dashed var(--ohkit-color-primary, #1890ff)",r.dragAreaRef.style.backgroundColor="rgba(173, 216, 230, 0.2)","x"===t?(r.dragAreaRef.style.width=o-i+n.width+"px",r.dragAreaRef.style.height="2px",r.dragAreaRef.style.left=i+"px",r.dragAreaRef.style.top=r.startTop+n.height/2+"px"):"y"===t?(r.dragAreaRef.style.width="2px",r.dragAreaRef.style.height=s-a+n.height+"px",r.dragAreaRef.style.left=r.startLeft+n.width/2+"px",r.dragAreaRef.style.top=a+"px"):(r.dragAreaRef.style.width=o-i+n.width+"px",r.dragAreaRef.style.height=s-a+n.height+"px",r.dragAreaRef.style.left=i+"px",r.dragAreaRef.style.top=a+"px"),r.dragAreaRef.style.display="block"}},r.hideDragArea=function(){r.dragAreaRef&&(r.dragAreaRef.style.display="none")},r.calcPosition=function(){var t=r.props.lockAxis,e=r.dragPositionBoundaries,i=e.minX,o=e.maxX,a=e.minY,s=e.maxY,n=r.getContainerRect(),d=n.height,l=n.width,h=r.startTop,c=r.startLeft;"y"!==t&&(c+=r.dX),"x"!==t&&(h+=r.dY);var g=p(h,a,s),f=p(c,i,o),u=d-g-r.dragBoxSize.height,m=l-f-r.dragBoxSize.width;g===r.state.top&&f===r.state.left&&r.state.bottom===u&&r.state.right===m||r.setState({top:g,left:f,bottom:u,right:m}),r.startTop=g,r.startLeft=f,r.dX=r.dY=0};var i=t.placement,s=t.offsetY,n=void 0===s?20:s,d=t.offsetX,l=void 0===d?20:d,h=(void 0===i?"bottom-right":i).split("-"),g=h[0],f=h[1];return r.state={top:"top"===g?n:void 0,bottom:"bottom"===g?n:void 0,left:"left"===f?l:void 0,right:"right"===f?l:void 0},r}var f,u;u=e,(f=g).prototype=Object.create(u.prototype),f.prototype.constructor=f,n(f,u);var m,v,x=g.prototype;return x.getContainer=function(t){void 0===t&&(t=!0);var e,r=this.props.positionMode,o=void 0===r?"fixed":r;return this.container&&t&&this.prePositionMode===o&&this.preDraggerRef===this.draggerRef||(this.prePositionMode=o,this.preDraggerRef=this.draggerRef,this.container="fixed"===o?(e=this.draggerRef)?i(e,function(t){return l(t,!1)},{excludeOwn:!0}):document.documentElement:function(t){return t?i(t,function(t){return l(t,!0)},{excludeOwn:!0}):document.body}(this.draggerRef)),this.container},x.getContainerRect=function(){var t=this.getContainer(!1);if(!t)return{width:window.innerWidth,height:window.innerHeight,left:0,top:0,scrollLeft:0,scrollTop:0,scrollerScrollLeft:0,scrollerScrollTop:0,borderLeftWidth:0,borderTopWidth:0};var e=t.getBoundingClientRect(),r=window.getComputedStyle(t),i=parseFloat(r.borderLeftWidth)||0,o=parseFloat(r.borderTopWidth)||0,a=parseFloat(r.borderRightWidth)||0,s=parseFloat(r.borderBottomWidth)||0;return{width:e.width/this.cachedScaleX-i-a-(t.offsetWidth-t.clientWidth-i-a),height:e.height/this.cachedScaleY-o-s-(t.offsetHeight-t.clientHeight-o-s),left:e.left/this.cachedScaleX,top:e.top/this.cachedScaleY,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,borderLeftWidth:i,borderTopWidth:o}},x.reportStartPosition=function(){if(this.draggerRef){var t=function(t){if(!t)return{scaleX:1,scaleY:1};var e=t.getBoundingClientRect(),r=1e4;return{scaleX:t.offsetWidth>0?Math.round(e.width/t.offsetWidth*r)/r:1,scaleY:t.offsetHeight>0?Math.round(e.height/t.offsetHeight*r)/r:1}}(this.getContainer()),e=t.scaleY;this.cachedScaleX=t.scaleX,this.cachedScaleY=e;var r=this.draggerRef.getBoundingClientRect(),i=r.top,o=r.left,a=this.getContainerRect();this.startTop=i/e-a.top+a.scrollTop-a.borderTopWidth,this.startLeft=o/e-a.left+a.scrollLeft-a.borderLeftWidth}},x.componentDidMount=function(){var t=this;this.reportStartPosition(),this.calcPosition(),this.__resizeDisposer=o(window,"resize",function(){t.calcPosition()})},x.componentWillUnmount=function(){var t,e,r,i,o;null==(t=this.__resizeDisposer)||t.call(this),null==(e=this.__bodyClassDisposer)||e.call(this),null==(r=this.__moveDisposer)||r.call(this),null==(i=this.__clickDisposer)||i.call(this),null==(o=this.__upDisposer)||o.call(this)},x.render=function(){var e=this,i=this.props,o=i.className,a=i.zIndex,n=i.children,d=i.showDragArea,l=i.positionMode,p=void 0===l?"fixed":l,h=this.startDrag,g=this.endDrag,f=s({zIndex:a},this.position,{position:p});/*#__PURE__*/return t.createElement(Fragment,null,d&&/*#__PURE__*/t.createElement("div",{className:c("drag-area"),ref:function(t){e.dragAreaRef=t},style:{display:"none",position:p,backgroundColor:"rgba(173, 216, 230, 0.2)",border:"1px dashed var(--ohkit-color-primary, #1890ff)",pointerEvents:"none",zIndex:(a||9999)-1,boxSizing:"border-box",borderRadius:"none"!==this.props.lockAxis?"2px":"0"}}),/*#__PURE__*/t.createElement("div",{className:r(c("container"),o),style:f,ref:function(t){e.draggerRef=t},onMouseDown:h,onMouseUp:g},n))},m=g,(v=[{key:"dragBoxSize",get:function(){var t=0,e=0;return this.draggerRef&&(t=this.draggerRef.offsetWidth,e=this.draggerRef.offsetHeight),{height:e,width:t}}},{key:"dragPositionBoundaries",get:function(){var t=this.props,e=t.boundsX,r=t.boundsY,i=t.placement,o=void 0===i?"bottom-right":i,a=this.dragBoxSize,s=this.getContainerRect(),n=s.width,d=s.height,l=o.split("-"),h=l[0],c=l[1],g={minX:0,maxX:Math.max(n-a.width,0),minY:0,maxY:Math.max(d-a.height,0)},f=g.minX,u=g.maxX,m=g.minY,v=g.maxY;if(e){var x=e[0],_=e[1];"left"===c?(void 0!==x&&(f=Math.max(f,x)),void 0!==_&&(u=Math.min(u,_))):void 0!==x&&void 0!==_?(f=Math.max(f,n-_-a.width),u=Math.min(u,n-x-a.width)):void 0!==x?u=Math.min(u,n-x-a.width):void 0!==_&&(f=Math.max(f,n-_-a.width))}if(r){var y=r[0],b=r[1];"top"===h?(void 0!==y&&(m=Math.max(m,y)),void 0!==b&&(v=Math.min(v,b))):void 0!==y&&void 0!==b?(m=Math.max(m,d-b-a.height),v=Math.min(v,d-y-a.height)):void 0!==y?v=Math.min(v,d-y-a.height):void 0!==b&&(m=Math.max(m,d-b-a.height))}return{minX:f=p(f,g.minX,g.maxX),maxX:u=p(u,f,g.maxX),minY:m=p(m,g.minY,g.maxY),maxY:v=p(v,m,g.maxY)}}},{key:"curPositionKey",get:function(){var t=this.props.placement;return t&&h.includes(t)||(t="bottom-right"),t.split("-")}},{key:"position",get:function(){var t=this.curPositionKey,e=t[0],r=t[1],i={};return void 0!==this.state[e]&&(i[e]=this.state[e]+"px"),void 0!==this.state[r]&&(i[r]=this.state[r]+"px"),i}}])&&function(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,d(i.key),i)}}(m.prototype,v),Object.defineProperty(m,"prototype",{writable:!1}),m}(t.Component);g.defaultProps={zIndex:9999,offsetX:20,offsetY:20,placement:"bottom-right",disabled:!1,lockAxis:"none",showDragArea:!1,positionMode:"fixed"};export{g as DraggableBox,c,g as default};
|
|
2
2
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/constants.ts","../src/index.tsx","../src/utils.ts"],"sourcesContent":["\nexport const ValidPlacement = ['top-left', 'top-right', 'bottom-left', 'bottom-right'] as const;\n","import React from 'react';\nimport {\n prefixClassname as p,\n classNames as cx,\n} from \"@ohkit/prefix-classname\";\nimport {addEventListener, addClass} from '@ohkit/dom-helper';\nimport {findFixedPositionParent, findAbsolutePositionParent, getScaleRatio} from './utils';\nimport {ValidPlacement} from './constants';\nimport {DraggableBoxProps, DraggableBoxState} from './type';\n\nimport './style.scss';\n\nexport const c = p(\"ohkit-draggable-box__\");\nexport class DraggableBox extends React.Component<DraggableBoxProps, DraggableBoxState> {\n static defaultProps: Partial<DraggableBoxProps> = {\n zIndex: 9999,\n offsetX: 20,\n offsetY: 20,\n placement: 'bottom-right',\n disabled: false,\n lockAxis: 'none',\n showDragArea: false,\n positionMode: 'fixed',\n };\n\n constructor(props: DraggableBoxProps) {\n super(props);\n \n const { placement = 'bottom-right', offsetY = 20, offsetX = 20 } = props;\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n // 简化状态初始化\n this.state = {\n top: placementY === 'top' ? offsetY : undefined,\n bottom: placementY === 'bottom' ? offsetY : undefined,\n left: placementX === 'left' ? offsetX : undefined,\n right: placementX === 'right' ? offsetX : undefined,\n };\n }\n\n getOtherYKey(yKey: 'top' | 'bottom') {\n return yKey === 'top' ? 'bottom' : 'top';\n }\n\n getOtherXKey(xKey: 'left' | 'right') {\n return xKey === 'left' ? 'right' : 'left';\n }\n\n // TODO:\n updatePosition(yKey: 'top' | 'bottom', xKey: 'left' | 'right') {\n const oYKey = this.getOtherYKey(yKey);\n const oXKey = this.getOtherXKey(xKey);\n this.setState({\n [oYKey]: this.dragPositionRang.height - (this.state[yKey] || 0),\n [oXKey]: this.dragPositionRang.width - (this.state[xKey] || 0),\n });\n }\n /**\n * 获取定位容器\n * 根据 positionMode 返回对应的定位父元素\n */\n private getContainer(): HTMLElement {\n const { positionMode = 'fixed' } = this.props;\n return positionMode === 'fixed' \n ? findFixedPositionParent(this.draggerRef) \n : findAbsolutePositionParent(this.draggerRef);\n }\n\n /**\n * 获取容器的尺寸和位置信息\n */\n private getContainerRect() {\n const { positionMode = 'fixed' } = this.props;\n const isFixed = positionMode === 'fixed';\n const container = this.getContainer();\n const containerRect = container.getBoundingClientRect();\n const rootScrollingElement = window.document.scrollingElement || window.document.body;\n const isRoot = container === window.document.body || container === window.document.documentElement;\n return {\n width: containerRect.width,\n height: containerRect.height,\n left: isFixed && isRoot ? Math.max(containerRect.left, 0) : containerRect.left + rootScrollingElement.scrollLeft,\n top: isFixed && isRoot ? Math.max(containerRect.top, 0) : containerRect.top + rootScrollingElement.scrollTop,\n scrollLeft: isFixed && isRoot ? 0 : container.scrollLeft, // container.scrollLeft,\n scrollTop: isFixed && isRoot ? 0 : container.scrollTop, // container.scrollTop\n scrollerScrollLeft: isFixed && isRoot ? 0 : rootScrollingElement.scrollLeft,\n scrollerScrollTop: isFixed && isRoot ? 0 : rootScrollingElement.scrollTop\n };\n }\n\n get windowSize() {\n const container = this.getContainer();\n const { clientWidth, clientHeight } = container;\n return {\n height: clientHeight,\n width: clientWidth\n };\n }\n\n get dragBoxSize() {\n let width = 0;\n let height = 0;\n if (this.draggerRef) {\n width = this.draggerRef.offsetWidth;\n height = this.draggerRef.offsetHeight;\n }\n return {\n height,\n width\n };\n }\n\n get dragPositionBoundaries() {\n const { boundsX, boundsY, placement = 'bottom-right' } = this.props;\n const dragSize = this.dragBoxSize;\n const windowSize = this.windowSize;\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n // 初始化边界\n let minX = 0;\n let maxX = windowSize.width - dragSize.width;\n let minY = 0;\n let maxY = windowSize.height - dragSize.height;\n\n // 处理X轴边界\n if (boundsX) {\n const [minBound, maxBound] = boundsX;\n \n if (placementX === 'left') {\n // 左边位置:boundsX=[左边最小距离, 左边最大距离]\n if (minBound !== undefined) minX = Math.max(minX, minBound);\n if (maxBound !== undefined) maxX = Math.min(maxX, maxBound);\n } else {\n // 右边位置:boundsX=[右边最小距离, 右边最大距离]\n // 直接使用边界值作为right的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minX = Math.max(minX, windowSize.width - maxBound - dragSize.width);\n maxX = Math.min(maxX, windowSize.width - minBound - dragSize.width);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxX = Math.min(maxX, windowSize.width - minBound - dragSize.width);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minX = Math.max(minX, windowSize.width - maxBound - dragSize.width);\n }\n \n // 确保最小边界不大于最大边界\n if (minX > maxX) {\n [minX, maxX] = [maxX, minX];\n }\n }\n }\n\n // 处理Y轴边界\n if (boundsY) {\n const [minBound, maxBound] = boundsY;\n \n if (placementY === 'top') {\n // 顶部位置:boundsY=[顶边最小距离, 顶边最大距离]\n if (minBound !== undefined) minY = Math.max(minY, minBound);\n if (maxBound !== undefined) maxY = Math.min(maxY, maxBound);\n } else {\n // 底部位置:boundsY=[底边最小距离, 底边最大距离]\n // 直接使用边界值作为bottom的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minY = Math.max(minY, windowSize.height - maxBound - dragSize.height);\n maxY = Math.min(maxY, windowSize.height - minBound - dragSize.height);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxY = Math.min(maxY, windowSize.height - minBound - dragSize.height);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minY = Math.max(minY, windowSize.height - maxBound - dragSize.height);\n }\n \n // 确保最小边界不大于最大边界\n if (minY > maxY) {\n [minY, maxY] = [maxY, minY];\n }\n }\n }\n\n return { minX, maxX, minY, maxY };\n }\n \n // 保持向后兼容\n get dragPositionRang() {\n const { maxX, maxY } = this.dragPositionBoundaries;\n return { width: maxX, height: maxY };\n }\n\n get curPositionKey() {\n let {placement} = this.props;\n if (!placement || !ValidPlacement.includes(placement)) {\n placement = 'bottom-right';\n }\n return placement.split('-') as ['top' | 'bottom', 'left' | 'right']; // [y, x]\n }\n\n get position() {\n const [y, x] = this.curPositionKey;\n const positionStyles: Record<string, string> = {};\n \n // 确保位置值存在且是有效的数字\n if (this.state[y] !== undefined) {\n positionStyles[y] = `${this.state[y]}px`;\n }\n if (this.state[x] !== undefined) {\n positionStyles[x] = `${this.state[x]}px`;\n }\n \n return positionStyles;\n }\n\n draggerRef: HTMLDivElement | null = null;\n\n isDragging = false;\n\n axisX?: number;\n axisY?: number;\n dX = 0;\n dY = 0;\n startTop = 0;\n startLeft = 0;\n\n // 缓存缩放比例,避免在 dragging 中频繁计算\n cachedScaleX = 1;\n cachedScaleY = 1;\n\n __moveDisposer?: () => void;\n __clickDisposer?: () => void;\n __bodyClassDisposer?: () => void;\n __upDisposer?: () => void;\n __resizeDisposer?: () => void;\n\n dragAreaRef: HTMLDivElement | null = null;\n\n reportStartPosition() {\n if (this.draggerRef) {\n const { top, left } = this.draggerRef.getBoundingClientRect();\n const containerRect = this.getContainerRect();\n // console.log(containerRect, 'containerRect');\n \n // 获取缩放比例\n const { scaleX, scaleY } = getScaleRatio(this.draggerRef);\n this.cachedScaleX = scaleX;\n this.cachedScaleY = scaleY;\n \n // 计算相对于容器的位置,并除以缩放比例得到未缩放的坐标\n this.startTop = (top - containerRect.top + containerRect.scrollerScrollTop) / scaleY + containerRect.scrollTop;\n this.startLeft = (left - containerRect.left + containerRect.scrollerScrollLeft) / scaleX + containerRect.scrollLeft;\n }\n }\n\n enableDrag = () => {\n this.reportStartPosition();\n this.__moveDisposer?.();\n this.__moveDisposer = addEventListener(document, 'mousemove', (evt) => {\n // INFO: 移动过程中禁止click事件\n if (!this.__clickDisposer) {\n const moveDistanse = Math.sqrt(Math.pow(this.dX, 2) + Math.pow(this.dY, 2));\n // INFO: 移动超过5px?? 确保用户有真实的移动意愿,而不是手抖~~\n if (moveDistanse > 5) {\n this.__clickDisposer = addEventListener(\n document,\n 'click',\n (evt) => {\n evt.stopPropagation();\n },\n true\n );\n this.__bodyClassDisposer = addClass([document.body, this.draggerRef], c('moving')) || undefined;\n \n // 显示拖拽区域\n if (this.props.showDragArea && this.dragAreaRef) {\n this.showDragArea();\n }\n }\n }\n this.dragging(evt);\n }, true);\n\n this.__upDisposer?.();\n this.__upDisposer = addEventListener(\n document,\n 'mouseup',\n (evt) => {\n this.endDrag();\n evt.stopPropagation();\n evt.preventDefault();\n },\n true\n );\n };\n\n startDrag = (evt: React.MouseEvent<HTMLDivElement>) => {\n // 判断鼠标非右击才继续执行\n if (evt.nativeEvent.button === 2) {\n return;\n }\n this.axisX = evt.nativeEvent.pageX;\n this.axisY = evt.nativeEvent.pageY;\n if (!this.props.disabled) {\n this.enableDrag();\n }\n };\n\n dragging = (evt: MouseEvent) => {\n this.isDragging = true;\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n \n // 使用缓存的缩放比例,避免频繁计算\n const scaleX = this.cachedScaleX;\n const scaleY = this.cachedScaleY;\n \n // 计算原始偏移量(需要除以缩放比例)\n this.dX = (evt.pageX - (this.axisX || 0)) / scaleX;\n this.dY = (evt.pageY - (this.axisY || 0)) / scaleY;\n \n // 应用方向锁定并计算变换值\n let translateX = this.dX;\n let translateY = this.dY;\n \n if (lockAxis === 'x') {\n translateY = 0; // 锁定Y方向\n } else if (lockAxis === 'y') {\n translateX = 0; // 锁定X方向\n }\n \n // 应用边界条件到允许移动的方向\n const potentialLeft = this.startLeft + translateX;\n const potentialTop = this.startTop + translateY;\n \n // X轴边界条件(在允许X轴移动时应用)\n if (lockAxis !== 'y') {\n if (potentialLeft < minX) {\n translateX = minX - this.startLeft;\n } else if (potentialLeft > maxX) {\n translateX = maxX - this.startLeft;\n }\n }\n \n // Y轴边界条件(在允许Y轴移动时应用)\n if (lockAxis !== 'x') {\n if (potentialTop < minY) {\n translateY = minY - this.startTop;\n } else if (potentialTop > maxY) {\n translateY = maxY - this.startTop;\n }\n }\n \n if (this.draggerRef) {\n this.draggerRef.style.transform = `translate(${translateX}px, ${translateY}px)`;\n }\n evt.stopPropagation();\n };\n\n endDrag = () => {\n if (this.isDragging) {\n this.calcPosition();\n if (this.draggerRef) {\n this.draggerRef.style.transform = '';\n }\n \n // 隐藏拖拽区域\n if (this.props.showDragArea) {\n this.hideDragArea();\n }\n }\n\n this.__moveDisposer?.();\n this.__moveDisposer = undefined;\n if (this.__clickDisposer) {\n requestAnimationFrame(() => {\n if (this.__clickDisposer) {\n this.__clickDisposer();\n this.__clickDisposer = undefined;\n }\n });\n }\n this.__upDisposer?.();\n this.__upDisposer = undefined;\n this.__bodyClassDisposer?.();\n this.__bodyClassDisposer = undefined;\n\n this.isDragging = false;\n };\n\n showDragArea = () => {\n if (!this.props.showDragArea || !this.dragAreaRef) return;\n \n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const dragSize = this.dragBoxSize;\n \n // 重置样式\n this.dragAreaRef.style.border = '1px dashed var(--ohkit-color-primary, #1890ff)';\n this.dragAreaRef.style.backgroundColor = 'rgba(173, 216, 230, 0.2)'; // 淡透蓝色\n \n if (lockAxis === 'x') {\n // 锁定Y方向,显示为水平虚线区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = '2px'; // 更细的虚线高度\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${this.startTop + dragSize.height / 2}px`;\n this.dragAreaRef.style.border = 'none';\n this.dragAreaRef.style.backgroundColor = 'transparent'; // 透明背景\n this.dragAreaRef.style.backgroundImage = 'linear-gradient(to right, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)';\n this.dragAreaRef.style.backgroundSize = '4px 2px'; // 虚线模式\n } else if (lockAxis === 'y') {\n // 锁定X方向,显示为垂直虚线区域\n this.dragAreaRef.style.width = '2px'; // 更细的虚线宽度\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${this.startLeft + dragSize.width / 2}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n this.dragAreaRef.style.border = 'none';\n this.dragAreaRef.style.backgroundColor = 'transparent'; // 透明背景\n this.dragAreaRef.style.backgroundImage = 'linear-gradient(to bottom, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)';\n this.dragAreaRef.style.backgroundSize = '2px 4px'; // 虚线模式\n } else {\n // 自由拖拽,显示完整区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n }\n \n this.dragAreaRef.style.display = 'block';\n };\n\n hideDragArea = () => {\n if (this.dragAreaRef) {\n this.dragAreaRef.style.display = 'none';\n }\n };\n calcPosition = () => {\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const containerSize = this.windowSize;\n \n // 计算新的位置\n let newTop = this.startTop;\n let newLeft = this.startLeft;\n \n if (lockAxis !== 'y') {\n newLeft += this.dX;\n }\n if (lockAxis !== 'x') {\n newTop += this.dY;\n }\n \n // 应用边界限制\n const realTop = Math.min(Math.max(minY, newTop), maxY);\n const realLeft = Math.min(Math.max(minX, newLeft), maxX);\n const realBottom = containerSize.height - realTop - this.dragBoxSize.height;\n const realRight = containerSize.width - realLeft - this.dragBoxSize.width;\n if (realTop !== this.state.top || realLeft !== this.state.left || this.state.bottom !== realBottom || this.state.right !== realRight) {\n // console.log(minY, maxY, this.startTop, this.dY, newTop, realTop, 'calcPosition y');\n // console.log(minX, maxX, this.startLeft, this.dX, newLeft, realLeft, 'calcPosition x');\n this.setState({\n top: realTop,\n left: realLeft,\n bottom: realBottom,\n right: realRight\n });\n }\n this.startTop = realTop;\n this.startLeft = realLeft;\n this.dX = this.dY = 0;\n };\n\n\n componentDidMount() {\n // 检查初始位置是否在边界范围内,如果不在则修正\n this.reportStartPosition();\n this.calcPosition();\n \n this.__resizeDisposer = addEventListener(window, 'resize', () => {\n this.calcPosition();\n });\n }\n\n componentWillUnmount() {\n this.__resizeDisposer?.();\n this.__bodyClassDisposer?.();\n this.__moveDisposer?.();\n this.__clickDisposer?.();\n this.__upDisposer?.();\n }\n\n render() {\n const { className, zIndex, children, showDragArea, positionMode = 'fixed' } = this.props;\n const { startDrag, endDrag } = this;\n const stl = {\n zIndex,\n ...this.position,\n position: positionMode\n };\n return (\n <>\n {showDragArea && (\n <div\n className={c('drag-area')}\n ref={(r) => {\n this.dragAreaRef = r;\n }}\n style={{\n display: 'none',\n position: positionMode,\n backgroundColor: 'rgba(173, 216, 230, 0.2)', // 淡透蓝色\n border: '1px dashed var(--ohkit-color-primary, #1890ff)',\n pointerEvents: 'none',\n zIndex: (zIndex || 9999) - 1,\n boxSizing: 'border-box',\n borderRadius: this.props.lockAxis !== 'none' ? '2px' : '0',\n }}\n />\n )}\n <div\n className={cx(c('container'), className)}\n style={stl}\n ref={(r) => {\n this.draggerRef = r;\n }}\n onMouseDown={startDrag}\n onMouseUp={endDrag}\n >\n {children}\n </div>\n </>\n );\n }\n}\n\nexport default DraggableBox;","import {findParent} from '@ohkit/dom-helper';\n\n/**\n * 查找影响 fixed 定位的父元素\n * 当父元素有 transform/filter/perspective 等属性时,fixed 定位会相对于该父元素\n */\nexport function findFixedPositionParent(dom?: HTMLElement | null): HTMLElement {\n if (!dom) {\n return document.documentElement;\n }\n const fixedPositionParent = findParent(dom, (parent) => {\n const style = window.getComputedStyle(parent);\n const transform = style.getPropertyValue('transform');\n const filter = style.getPropertyValue('filter');\n const perspective = style.getPropertyValue('perspective');\n \n // 检查是否有影响 fixed 定位的属性\n if (transform !== 'none' || filter !== 'none' || perspective !== 'none') {\n return true;\n }\n }, {excludeOwn: true}) || document.documentElement; // 没有找到,返回 window(通过 document.documentElement)\n return fixedPositionParent;\n}\n\n/**\n * 查找 absolute 定位的父元素\n * 查找最近的 position 不为 static 的元素\n */\nexport function findAbsolutePositionParent(dom?: HTMLElement | null): HTMLElement {\n if (!dom) {\n return document.body;\n }\n return findParent(dom, (parent) => {\n const style = window.getComputedStyle(parent);\n const position = style.getPropertyValue('position');\n if (position !== 'static') {\n return true;\n }\n }, {excludeOwn: true}) || document.body;\n}\n\n/**\n * 获取容器的缩放比例\n * 通过比较元素的实际尺寸和 getBoundingClientRect 返回的尺寸来计算缩放比例\n */\nexport function getScaleRatio(dom?: HTMLElement | null): { scaleX: number; scaleY: number } {\n if (!dom) {\n return { scaleX: 1, scaleY: 1 };\n }\n // 通过比较 offsetWidth 和 getBoundingClientRect().width 来获取缩放比例\n const rect = dom.getBoundingClientRect();\n // 扩大10倍进行计算,避免浮点数精度问题\n const scaleX = dom.offsetWidth > 0 ? Math.round(rect.width / dom.offsetWidth * 10) / 10 : 1;\n const scaleY = dom.offsetHeight > 0 ? Math.round(rect.height / dom.offsetHeight * 10) / 10 : 1;\n // console.log('scaleX', scaleX, 'scaleY', scaleY);\n return { scaleX, scaleY };\n}\n"],"names":["ValidPlacement","c","p","DraggableBox","_React$Component","props","_this","call","this","draggerRef","isDragging","axisX","axisY","dX","dY","startTop","startLeft","cachedScaleX","cachedScaleY","__moveDisposer","__clickDisposer","__bodyClassDisposer","__upDisposer","__resizeDisposer","dragAreaRef","enableDrag","reportStartPosition","addEventListener","document","evt","Math","sqrt","pow","stopPropagation","addClass","body","undefined","showDragArea","dragging","endDrag","preventDefault","startDrag","nativeEvent","button","pageX","pageY","disabled","lockAxis","_this$dragPositionBou","dragPositionBoundaries","minX","maxX","minY","maxY","scaleY","translateX","translateY","potentialLeft","potentialTop","style","transform","calcPosition","hideDragArea","requestAnimationFrame","_this$dragPositionBou2","dragSize","dragBoxSize","border","backgroundColor","width","height","left","top","backgroundImage","backgroundSize","display","_this$dragPositionBou3","containerSize","windowSize","newTop","newLeft","realTop","min","max","realLeft","realBottom","realRight","state","bottom","right","setState","_props$placement","placement","_props$offsetY","offsetY","_props$offsetX","offsetX","_placement$split","split","placementY","placementX","_proto","prototype","getOtherYKey","yKey","getOtherXKey","xKey","updatePosition","_this$setState","oYKey","oXKey","dragPositionRang","getContainer","dom","_this$props$positionM","positionMode","findParent","parent","window","getComputedStyle","getPropertyValue","filter","perspective","excludeOwn","documentElement","findAbsolutePositionParent","getContainerRect","_this$props$positionM2","isFixed","container","containerRect","getBoundingClientRect","rootScrollingElement","scrollingElement","isRoot","scrollLeft","scrollTop","scrollerScrollLeft","scrollerScrollTop","_this$draggerRef$getB","_getScaleRatio","scaleX","rect","offsetWidth","round","offsetHeight","getScaleRatio","componentDidMount","_this2","componentWillUnmount","_this$__resizeDispose","_this$__bodyClassDisp","_this$__moveDisposer","_this$__clickDisposer","_this$__upDisposer","render","_this3","_this$props","className","zIndex","children","_this$props$positionM3","stl","_extends","position","React","createElement","Fragment","ref","r","pointerEvents","boxSizing","borderRadius","cx","onMouseDown","onMouseUp","key","get","clientHeight","clientWidth","_this$props2","boundsX","boundsY","_this$props2$placemen","_placement$split2","minBound","maxBound","_ref","_ref2","_this$dragPositionBou4","includes","_this$curPositionKey","curPosition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ASmH,EAAWxH,EAASK,cAC1ClC,IAAbqJ,EAEPpI,EAAOvB,KAAKoD,IAAI7B,EAAMyB,EAAWR,OAASmH,EAAWxH,EAASK,aAC1ClC,IAAbsJ,IAEPtI,EAAOtB,KAAKqD,IAAI/B,EAAM0B,EAAWR,OAASoH,EAAWzH,EAASK,SAI9DlB,EAAOC,EAAM,CAAAuI,IAAAA,EACE,CAACvI,EAAMD,GAArBA,EAAIwI,EAAEvI,GAAAA,EAAIuI,EAAA,EACd,CAER,CAED,MAAO,CAAE1I,KAAAA,EAAMC,KAAAA,EAAMC,KAAAA,EAAMC,KAAAA,EAC/B,GAAC,CAAA2H,IAAAC,mBAAAA,IAGD,WACI,IAAAY,EAAuBrL,KAAKyC,uBAC5B,MAAO,CAAEoB,MADGwH,EAAJ1I,KACcmB,OADJuH,EAAJxI,KAElB,IAAC2H,IAAA,iBAAAC,IAED,WACI,IAAKrF,EAAapF,KAAKH,MAAlBuF,UAIL,OAHKA,GAAc5F,EAAe8L,SAASlG,KACvCA,EAAY,gBAETA,EAAUM,MAAM,IAC3B,GAAC8E,CAAAA,eAAAC,IAED,WACI,IAAAc,EAAevL,KAAKwL,eAAbC,EAACF,EAAEG,GAAAA,EAACH,EAAA,GACLI,EAAyC,CAAA,EAU/C,YAPsB/J,IAAlB5B,KAAK+E,MAAM0G,KACXE,EAAeF,GAAQzL,KAAK+E,MAAM0G,cAEhB7J,IAAlB5B,KAAK+E,MAAM2G,KACXC,EAAeD,GAAQ1L,KAAK+E,MAAM2G,GACrC,MAEMC,CACX,iPAvM8B9B,CAARjK,CAAQiK,EAAM+B,WAA3BjM,EACFkM,aAA2C,CAC9CtC,OAAQ,KACR/D,QAAS,GACTF,QAAS,GACTF,UAAW,eACX9C,UAAU,EACVC,SAAU,OACVV,cAAc,EACd8E,aAAc"}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/utils.ts","../src/constants.ts","../src/index.tsx"],"sourcesContent":["import {findParent} from '@ohkit/dom-helper';\n\n/**\n * 检查元素是否创建了新的定位上下文(包含块)\n * @param element 要检查的元素\n * @param includePosition 是否检查position属性(absolute/relative/fixed)\n */\nexport function isPositioningContextCreator(element: HTMLElement, includePosition: boolean): boolean {\n const style = window.getComputedStyle(element);\n const position = style.getPropertyValue('position');\n const transform = style.getPropertyValue('transform');\n const filter = style.getPropertyValue('filter');\n const perspective = style.getPropertyValue('perspective');\n const contain = style.getPropertyValue('contain');\n const willChange = style.getPropertyValue('will-change');\n \n return (includePosition && position !== 'static') || \n transform !== 'none' || \n filter !== 'none' || \n perspective !== 'none' ||\n contain.includes('paint') ||\n contain.includes('layout') ||\n contain.includes('strict') ||\n willChange.includes('transform') ||\n willChange.includes('perspective') ||\n willChange.includes('filter');\n}\n\n/**\n * 查找影响 fixed 定位的父元素\n * 当父元素有 transform/filter/perspective/contain/will-change 等属性时,fixed 定位会相对于该父元素\n */\nexport function findFixedPositionParent(dom?: HTMLElement | null) {\n if (!dom) {\n return document.documentElement;\n }\n const fixedPositionParent = findParent(dom, (parent) => {\n return isPositioningContextCreator(parent, false);\n }, {excludeOwn: true}); // 没有找到,返回 window(通过 document.documentElement)\n return fixedPositionParent;\n}\n\n/**\n * 查找 absolute 定位的父元素\n * 查找最近的包含块创建者,包含所有可能影响absolute定位的属性\n */\nexport function findAbsolutePositionParent(dom?: HTMLElement | null) {\n if (!dom) {\n return document.body;\n }\n return findParent(dom, (parent) => {\n return isPositioningContextCreator(parent, true);\n }, {excludeOwn: true});\n}\n\n/**\n * 获取容器的缩放比例\n * 通过比较元素的实际尺寸和 getBoundingClientRect 返回的尺寸来计算缩放比例\n */\nexport function getScaleRatio(dom?: HTMLElement | null): { scaleX: number; scaleY: number } {\n if (!dom) {\n return { scaleX: 1, scaleY: 1 };\n }\n // 通过比较 offsetWidth 和 getBoundingClientRect().width 来获取缩放比例\n const rect = dom.getBoundingClientRect();\n let scaleX = 1;\n let scaleY = 1;\n // 扩大{magnification}倍进行计算, 相当于保留小数点后4位\n const magnification = 10000;\n scaleX = dom.offsetWidth > 0 ? Math.round(rect.width / dom.offsetWidth * magnification) / magnification : 1;\n scaleY = dom.offsetHeight > 0 ? Math.round(rect.height / dom.offsetHeight * magnification) / magnification : 1;\n // console.log('rect.width dom.offsetWidth', rect.width, dom.offsetWidth);\n // console.log('rect.height dom.offsetHeight', rect.height, dom.offsetHeight);\n // console.log('scaleX', scaleX, 'scaleY', scaleY);\n return { scaleX, scaleY };\n}\n\n/**\n * 限制数值在指定范围内\n * \n * @param value 要限制的数值\n * @param min 最小值\n * @param max 最大值\n * @returns 限制后的数值,确保在 [min, max] 范围内\n */\nexport function clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n","\nexport const ValidPlacement = ['top-left', 'top-right', 'bottom-left', 'bottom-right'] as const;\n","import React from 'react';\nimport {\n prefixClassname as p,\n classNames as cx,\n} from \"@ohkit/prefix-classname\";\nimport {addEventListener, addClass} from '@ohkit/dom-helper';\nimport {findFixedPositionParent, findAbsolutePositionParent, getScaleRatio, clamp} from './utils';\nimport {ValidPlacement} from './constants';\nimport {DraggableBoxProps, DraggableBoxState} from './type';\n\nimport './style.scss';\n\nexport const c = p(\"ohkit-draggable-box__\");\nexport class DraggableBox extends React.Component<DraggableBoxProps, DraggableBoxState> {\n static defaultProps: Partial<DraggableBoxProps> = {\n zIndex: 9999,\n offsetX: 20,\n offsetY: 20,\n placement: 'bottom-right',\n disabled: false,\n lockAxis: 'none',\n showDragArea: false,\n positionMode: 'fixed',\n };\n\n constructor(props: DraggableBoxProps) {\n super(props);\n \n const { placement = 'bottom-right', offsetY = 20, offsetX = 20 } = props;\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n // 简化状态初始化\n this.state = {\n top: placementY === 'top' ? offsetY : undefined,\n bottom: placementY === 'bottom' ? offsetY : undefined,\n left: placementX === 'left' ? offsetX : undefined,\n right: placementX === 'right' ? offsetX : undefined,\n };\n }\n\n private prePositionMode: DraggableBoxProps['positionMode'];\n private preDraggerRef: HTMLElement | null = null;\n private container: HTMLElement | null = null;\n /**\n * 获取定位容器\n * 根据 positionMode 返回对应的定位父元素\n */\n private getContainer(useCache = true) {\n const { positionMode = 'fixed' } = this.props;\n if (!this.container || !useCache || this.prePositionMode !== positionMode || this.preDraggerRef !== this.draggerRef) {\n this.prePositionMode = positionMode;\n this.preDraggerRef = this.draggerRef;\n this.container = positionMode === 'fixed' \n ? findFixedPositionParent(this.draggerRef) \n : findAbsolutePositionParent(this.draggerRef);\n }\n return this.container;\n }\n\n /**\n * 获取容器的尺寸和位置信息\n */\n private getContainerRect() {\n const container = this.getContainer(false);\n if (!container) {\n return {\n width: window.innerWidth,\n height: window.innerHeight,\n left: 0,\n top: 0,\n scrollLeft: 0,\n scrollTop: 0,\n scrollerScrollLeft: 0,\n scrollerScrollTop: 0,\n borderLeftWidth: 0,\n borderTopWidth: 0\n };\n }\n const containerRect = container.getBoundingClientRect();\n \n // 获取容器的border宽度(仅 top, left 对坐标计算有影响)\n const containerStyle = window.getComputedStyle(container);\n const borderLeftWidth = parseFloat(containerStyle.borderLeftWidth) || 0;\n const borderTopWidth = parseFloat(containerStyle.borderTopWidth) || 0;\n const borderRightWidth = parseFloat(containerStyle.borderRightWidth) || 0;\n const borderBottomWidth = parseFloat(containerStyle.borderBottomWidth) || 0;\n const yScrollerWidth = container.offsetWidth - container.clientWidth - borderLeftWidth - borderRightWidth;\n const xScrollerHeight = container.offsetHeight - container.clientHeight - borderTopWidth - borderBottomWidth;\n // console.log('yScrollerWidth, xScrollerHeight', yScrollerWidth, xScrollerHeight);\n\n return {\n width: containerRect.width / this.cachedScaleX - borderLeftWidth - borderRightWidth - yScrollerWidth,\n height: containerRect.height / this.cachedScaleY - borderTopWidth - borderBottomWidth - xScrollerHeight,\n left: containerRect.left / this.cachedScaleX,\n top: containerRect.top / this.cachedScaleY,\n scrollLeft: container.scrollLeft,\n scrollTop: container.scrollTop,\n borderLeftWidth: borderLeftWidth,\n borderTopWidth: borderTopWidth,\n };\n }\n\n get dragBoxSize() {\n let width = 0;\n let height = 0;\n if (this.draggerRef) {\n width = this.draggerRef.offsetWidth;\n height = this.draggerRef.offsetHeight;\n }\n return {\n height,\n width\n };\n }\n\n get dragPositionBoundaries() {\n const { boundsX, boundsY, placement = 'bottom-right' } = this.props;\n const dragSize = this.dragBoxSize;\n const {width: containerWidth, height: containerHeight} = this.getContainerRect();\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n const defaultBounds = {\n minX: 0,\n maxX: Math.max(containerWidth - dragSize.width, 0),\n minY: 0,\n maxY: Math.max(containerHeight- dragSize.height, 0),\n };\n // 初始化边界\n let {minX, maxX, minY, maxY} = defaultBounds\n\n // 处理X轴边界\n if (boundsX) {\n const [minBound, maxBound] = boundsX;\n if (placementX === 'left') {\n // 左边位置:boundsX=[左边最小距离, 左边最大距离]\n if (minBound !== undefined) minX = Math.max(minX, minBound);\n if (maxBound !== undefined) maxX = Math.min(maxX, maxBound);\n } else {\n // 右边位置:boundsX=[右边最小距离, 右边最大距离]\n // 直接使用边界值作为right的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minX = Math.max(minX, containerWidth - maxBound - dragSize.width);\n maxX = Math.min(maxX, containerWidth - minBound - dragSize.width);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxX = Math.min(maxX, containerWidth - minBound - dragSize.width);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minX = Math.max(minX, containerWidth - maxBound - dragSize.width);\n }\n }\n }\n\n // 处理Y轴边界\n if (boundsY) {\n const [minBound, maxBound] = boundsY;\n \n if (placementY === 'top') {\n // 顶部位置:boundsY=[顶边最小距离, 顶边最大距离]\n if (minBound !== undefined) minY = Math.max(minY, minBound);\n if (maxBound !== undefined) maxY = Math.min(maxY, maxBound);\n } else {\n // 底部位置:boundsY=[底边最小距离, 底边最大距离]\n // 直接使用边界值作为bottom的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minY = Math.max(minY, containerHeight - maxBound - dragSize.height);\n maxY = Math.min(maxY, containerHeight - minBound - dragSize.height);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxY = Math.min(maxY, containerHeight - minBound - dragSize.height);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minY = Math.max(minY, containerHeight - maxBound - dragSize.height);\n }\n }\n }\n // 确保各个边界值在默认范围内\n minX = clamp(minX, defaultBounds.minX, defaultBounds.maxX);\n maxX = clamp(maxX, minX, defaultBounds.maxX);\n minY = clamp(minY, defaultBounds.minY, defaultBounds.maxY);\n maxY = clamp(maxY, minY, defaultBounds.maxY);\n\n return { minX, maxX, minY, maxY };\n }\n\n get curPositionKey() {\n let {placement} = this.props;\n if (!placement || !ValidPlacement.includes(placement)) {\n placement = 'bottom-right';\n }\n return placement.split('-') as ['top' | 'bottom', 'left' | 'right']; // [y, x]\n }\n\n get position() {\n const [y, x] = this.curPositionKey;\n const positionStyles: Record<string, string> = {};\n \n // 确保位置值存在且是有效的数字\n if (this.state[y] !== undefined) {\n positionStyles[y] = `${this.state[y]}px`;\n }\n if (this.state[x] !== undefined) {\n positionStyles[x] = `${this.state[x]}px`;\n }\n \n return positionStyles;\n }\n\n draggerRef: HTMLDivElement | null = null;\n\n isDragging = false;\n\n axisX?: number;\n axisY?: number;\n dX = 0;\n dY = 0;\n startTop = 0;\n startLeft = 0;\n\n // 缓存缩放比例,避免在 dragging 中频繁计算\n cachedScaleX = 1;\n cachedScaleY = 1;\n\n __moveDisposer?: () => void;\n __clickDisposer?: () => void;\n __bodyClassDisposer?: () => void;\n __upDisposer?: () => void;\n __resizeDisposer?: () => void;\n\n dragAreaRef: HTMLDivElement | null = null;\n\n reportStartPosition() {\n if (this.draggerRef) {\n // 获取缩放比例\n const { scaleX, scaleY } = getScaleRatio(this.getContainer());\n this.cachedScaleX = scaleX;\n this.cachedScaleY = scaleY;\n const { top, left } = this.draggerRef.getBoundingClientRect();\n const containerRect = this.getContainerRect();\n // console.log(containerRect, 'containerRect');\n \n // 计算相对于容器的位置,并除以缩放比例得到未缩放的坐标\n this.startTop = top / scaleY - containerRect.top + containerRect.scrollTop - containerRect.borderTopWidth;\n this.startLeft = left / scaleY - containerRect.left + containerRect.scrollLeft - containerRect.borderLeftWidth;\n }\n }\n\n enableDrag = () => {\n this.reportStartPosition();\n this.__moveDisposer?.();\n this.__moveDisposer = addEventListener(document, 'mousemove', (evt) => {\n // INFO: 移动过程中禁止click事件\n if (!this.__clickDisposer) {\n const moveDistanse = Math.sqrt(Math.pow(this.dX, 2) + Math.pow(this.dY, 2));\n // INFO: 移动超过5px?? 确保用户有真实的移动意愿,而不是手抖~~\n if (moveDistanse > 5) {\n this.__clickDisposer = addEventListener(\n document,\n 'click',\n (evt) => {\n evt.stopPropagation();\n },\n true\n );\n this.__bodyClassDisposer = addClass([document.body, this.draggerRef], c('moving')) || undefined;\n \n // 显示拖拽区域\n if (this.props.showDragArea && this.dragAreaRef) {\n this.showDragArea();\n }\n }\n }\n this.dragging(evt);\n }, true);\n\n this.__upDisposer?.();\n this.__upDisposer = addEventListener(\n document,\n 'mouseup',\n (evt) => {\n this.endDrag();\n evt.stopPropagation();\n evt.preventDefault();\n },\n true\n );\n };\n\n startDrag = (evt: React.MouseEvent<HTMLDivElement>) => {\n // 判断鼠标非右击才继续执行\n if (evt.nativeEvent.button === 2) {\n return;\n }\n this.axisX = evt.nativeEvent.pageX;\n this.axisY = evt.nativeEvent.pageY;\n if (!this.props.disabled) {\n this.enableDrag();\n }\n };\n\n dragging = (evt: MouseEvent) => {\n this.isDragging = true;\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n \n // 使用缓存的缩放比例,避免频繁计算\n const scaleX = this.cachedScaleX;\n const scaleY = this.cachedScaleY;\n \n // 计算原始偏移量(需要除以缩放比例)\n this.dX = (evt.pageX - (this.axisX || 0)) / scaleX;\n this.dY = (evt.pageY - (this.axisY || 0)) / scaleY;\n \n // 应用方向锁定并计算变换值\n let translateX = this.dX;\n let translateY = this.dY;\n \n if (lockAxis === 'x') {\n translateY = 0; // 锁定Y方向\n } else if (lockAxis === 'y') {\n translateX = 0; // 锁定X方向\n }\n \n // 应用边界条件到允许移动的方向\n const potentialLeft = this.startLeft + translateX;\n const potentialTop = this.startTop + translateY;\n \n // X轴边界条件(在允许X轴移动时应用)\n if (lockAxis !== 'y') {\n if (potentialLeft < minX) {\n translateX = minX - this.startLeft;\n } else if (potentialLeft > maxX) {\n translateX = maxX - this.startLeft;\n }\n }\n \n // Y轴边界条件(在允许Y轴移动时应用)\n if (lockAxis !== 'x') {\n if (potentialTop < minY) {\n translateY = minY - this.startTop;\n } else if (potentialTop > maxY) {\n translateY = maxY - this.startTop;\n }\n }\n \n if (this.draggerRef) {\n this.draggerRef.style.transform = `translate(${translateX}px, ${translateY}px)`;\n }\n evt.stopPropagation();\n };\n\n endDrag = () => {\n if (this.isDragging) {\n this.calcPosition();\n if (this.draggerRef) {\n this.draggerRef.style.transform = '';\n }\n \n // 隐藏拖拽区域\n if (this.props.showDragArea) {\n this.hideDragArea();\n }\n }\n\n this.__moveDisposer?.();\n this.__moveDisposer = undefined;\n if (this.__clickDisposer) {\n requestAnimationFrame(() => {\n if (this.__clickDisposer) {\n this.__clickDisposer();\n this.__clickDisposer = undefined;\n }\n });\n }\n this.__upDisposer?.();\n this.__upDisposer = undefined;\n this.__bodyClassDisposer?.();\n this.__bodyClassDisposer = undefined;\n\n this.isDragging = false;\n };\n\n showDragArea = () => {\n if (!this.props.showDragArea || !this.dragAreaRef) return;\n \n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const dragSize = this.dragBoxSize;\n \n // 重置样式\n this.dragAreaRef.style.border = '1px dashed var(--ohkit-color-primary, #1890ff)';\n this.dragAreaRef.style.backgroundColor = 'rgba(173, 216, 230, 0.2)'; // 淡透蓝色\n \n if (lockAxis === 'x') {\n // 锁定Y方向,显示为水平虚线区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = '2px'; // 更细的虚线高度\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${this.startTop + dragSize.height / 2}px`;\n } else if (lockAxis === 'y') {\n // 锁定X方向,显示为垂直虚线区域\n this.dragAreaRef.style.width = '2px'; // 更细的虚线宽度\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${this.startLeft + dragSize.width / 2}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n } else {\n // 自由拖拽,显示完整区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n }\n \n this.dragAreaRef.style.display = 'block';\n };\n\n hideDragArea = () => {\n if (this.dragAreaRef) {\n this.dragAreaRef.style.display = 'none';\n }\n };\n calcPosition = () => {\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const {height, width} = this.getContainerRect();\n \n // 计算新的位置\n let newTop = this.startTop;\n let newLeft = this.startLeft;\n \n if (lockAxis !== 'y') {\n newLeft += this.dX;\n }\n if (lockAxis !== 'x') {\n newTop += this.dY;\n }\n \n // 应用边界限制\n const realTop = clamp(newTop, minY, maxY);\n const realLeft = clamp(newLeft, minX, maxX);\n const realBottom = height - realTop - this.dragBoxSize.height;\n const realRight = width - realLeft - this.dragBoxSize.width;\n if (realTop !== this.state.top || realLeft !== this.state.left || this.state.bottom !== realBottom || this.state.right !== realRight) {\n // console.log(minY, maxY, this.startTop, this.dY, newTop, realTop, 'minY, maxY, this.startTop, this.dY, newTop, realTop --- calcPosition y');\n // console.log(minX, maxX, this.startLeft, this.dX, newLeft, realLeft, 'minX, maxX, this.startLeft, this.dX, newLeft, realLeft ---calcPosition x');\n this.setState({\n top: realTop,\n left: realLeft,\n bottom: realBottom,\n right: realRight\n });\n }\n this.startTop = realTop;\n this.startLeft = realLeft;\n this.dX = this.dY = 0;\n };\n\n\n componentDidMount() {\n // 检查初始位置是否在边界范围内,如果不在则修正\n this.reportStartPosition();\n this.calcPosition();\n \n this.__resizeDisposer = addEventListener(window, 'resize', () => {\n this.calcPosition();\n });\n }\n\n componentWillUnmount() {\n this.__resizeDisposer?.();\n this.__bodyClassDisposer?.();\n this.__moveDisposer?.();\n this.__clickDisposer?.();\n this.__upDisposer?.();\n }\n\n render() {\n const { className, zIndex, children, showDragArea, positionMode = 'fixed' } = this.props;\n const { startDrag, endDrag } = this;\n const stl = {\n zIndex,\n ...this.position,\n position: positionMode\n };\n return (\n <>\n {showDragArea && (\n <div\n className={c('drag-area')}\n ref={(r) => {\n this.dragAreaRef = r;\n }}\n style={{\n display: 'none',\n position: positionMode,\n backgroundColor: 'rgba(173, 216, 230, 0.2)', // 淡透蓝色\n border: '1px dashed var(--ohkit-color-primary, #1890ff)',\n pointerEvents: 'none',\n zIndex: (zIndex || 9999) - 1,\n boxSizing: 'border-box',\n borderRadius: this.props.lockAxis !== 'none' ? '2px' : '0',\n }}\n />\n )}\n <div\n className={cx(c('container'), className)}\n style={stl}\n ref={(r) => {\n this.draggerRef = r;\n }}\n onMouseDown={startDrag}\n onMouseUp={endDrag}\n >\n {children}\n </div>\n </>\n );\n }\n}\n\nexport default DraggableBox;"],"names":["isPositioningContextCreator","element","includePosition","style","window","getComputedStyle","position","getPropertyValue","transform","filter","perspective","contain","willChange","includes","clamp","value","min","max","Math","ValidPlacement","c","p","DraggableBox","_React$Component","props","_this","call","this","prePositionMode","preDraggerRef","container","draggerRef","isDragging","axisX","axisY","dX","dY","startTop","startLeft","cachedScaleX","cachedScaleY","__moveDisposer","__clickDisposer","__bodyClassDisposer","__upDisposer","__resizeDisposer","dragAreaRef","enableDrag","reportStartPosition","addEventListener","document","evt","sqrt","pow","stopPropagation","addClass","body","undefined","showDragArea","dragging","endDrag","preventDefault","startDrag","nativeEvent","button","pageX","pageY","disabled","lockAxis","_this$dragPositionBou","dragPositionBoundaries","minX","maxX","minY","maxY","scaleY","translateX","translateY","potentialLeft","potentialTop","calcPosition","hideDragArea","requestAnimationFrame","_this$dragPositionBou2","dragSize","dragBoxSize","border","backgroundColor","width","height","left","top","display","_this$dragPositionBou3","_this$getContainerRec","getContainerRect","newTop","newLeft","realTop","realLeft","realBottom","realRight","state","bottom","right","setState","_props$placement","placement","_props$offsetY","offsetY","_props$offsetX","offsetX","_placement$split","split","placementY","placementX","_proto","prototype","getContainer","useCache","dom","_this$props$positionM","positionMode","findParent","parent","excludeOwn","documentElement","findAbsolutePositionParent","innerWidth","innerHeight","scrollLeft","scrollTop","scrollerScrollLeft","scrollerScrollTop","borderLeftWidth","borderTopWidth","containerRect","getBoundingClientRect","containerStyle","parseFloat","borderRightWidth","borderBottomWidth","offsetWidth","clientWidth","offsetHeight","clientHeight","_getScaleRatio","scaleX","rect","magnification","round","getScaleRatio","_this$draggerRef$getB","componentDidMount","_this2","componentWillUnmount","_this$__resizeDispose","_this$__bodyClassDisp","_this$__moveDisposer","_this$__clickDisposer","_this$__upDisposer","render","_this3","_this$props","className","zIndex","children","_this$props$positionM2","stl","_extends","React","createElement","Fragment","ref","r","pointerEvents","boxSizing","borderRadius","cx","onMouseDown","onMouseUp","key","get","_this$props2","boundsX","boundsY","_this$props2$placemen","_this$getContainerRec2","containerWidth","containerHeight","_placement$split2","defaultBounds","minBound","maxBound","_this$curPositionKey","curPositionKey","y","x","positionStyles","Component","defaultProps"],"mappings":"kyBAOgB,SAAAA,EAA4BC,EAAsBC,GAC9D,IAAMC,EAAQC,OAAOC,iBAAiBJ,GAChCK,EAAWH,EAAMI,iBAAiB,YAClCC,EAAYL,EAAMI,iBAAiB,aACnCE,EAASN,EAAMI,iBAAiB,UAChCG,EAAcP,EAAMI,iBAAiB,eACrCI,EAAUR,EAAMI,i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2D,EAAMsH,EAActH,KAAMsH,EAAcrH,MAG1BA,KAF3BA,EAAO5D,EAAM4D,EAAMD,EAAMsH,EAAcrH,MAG3C,GAAC2G,CAAAA,qBAAAC,IAED,WACI,IAAK3E,EAAahF,KAAKH,MAAlBmF,UAIL,OAHKA,GAAcxF,EAAeN,SAAS8F,KACvCA,EAAY,gBAETA,EAAUM,MAAM,IAC3B,GAACoE,CAAAA,eAAAC,IAED,WACI,IAAAY,EAAevK,KAAKwK,eAAbC,EAACF,EAAA,GAAEG,EAACH,KACLI,EAAyC,CAAA,EAU/C,YAPsB7I,IAAlB9B,KAAK2E,MAAM8F,KACXE,EAAeF,GAAQzK,KAAK2E,MAAM8F,GAAE,WAElB3I,IAAlB9B,KAAK2E,MAAM+F,KACXC,EAAeD,GAAQ1K,KAAK2E,MAAM+F,GAAE,MAGjCC,CACX,iPAAC,CAjMqB,CAAQ5B,EAAM6B,WAA3BjL,EACFkL,aAA2C,CAC9CnC,OAAQ,KACRtD,QAAS,GACTF,QAAS,GACTF,UAAW,eACXxC,UAAU,EACVC,SAAU,OACVV,cAAc,EACdgE,aAAc"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=require("react"),e=require("@ohkit/prefix-classname"),r=require("@ohkit/dom-helper");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=/*#__PURE__*/o(t);function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var o in r)({}).hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},a.apply(null,arguments)}function n(t,e){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},n(t,e)}function s(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}var d=["top-left","top-right","bottom-left","bottom-right"],l=e.prefixClassname("ohkit-draggable-box__"),g=/*#__PURE__*/function(t){function o(e){var o;(o=t.call(this,e)||this).draggerRef=null,o.isDragging=!1,o.axisX=void 0,o.axisY=void 0,o.dX=0,o.dY=0,o.startTop=0,o.startLeft=0,o.cachedScaleX=1,o.cachedScaleY=1,o.__moveDisposer=void 0,o.__clickDisposer=void 0,o.__bodyClassDisposer=void 0,o.__upDisposer=void 0,o.__resizeDisposer=void 0,o.dragAreaRef=null,o.enableDrag=function(){o.reportStartPosition(),null==o.__moveDisposer||o.__moveDisposer(),o.__moveDisposer=r.addEventListener(document,"mousemove",function(t){o.__clickDisposer||Math.sqrt(Math.pow(o.dX,2)+Math.pow(o.dY,2))>5&&(o.__clickDisposer=r.addEventListener(document,"click",function(t){t.stopPropagation()},!0),o.__bodyClassDisposer=r.addClass([document.body,o.draggerRef],l("moving"))||void 0,o.props.showDragArea&&o.dragAreaRef&&o.showDragArea()),o.dragging(t)},!0),null==o.__upDisposer||o.__upDisposer(),o.__upDisposer=r.addEventListener(document,"mouseup",function(t){o.endDrag(),t.stopPropagation(),t.preventDefault()},!0)},o.startDrag=function(t){2!==t.nativeEvent.button&&(o.axisX=t.nativeEvent.pageX,o.axisY=t.nativeEvent.pageY,o.props.disabled||o.enableDrag())},o.dragging=function(t){o.isDragging=!0;var e=o.props.lockAxis,r=o.dragPositionBoundaries,i=r.minX,a=r.maxX,n=r.minY,s=r.maxY,d=o.cachedScaleY;o.dX=(t.pageX-(o.axisX||0))/o.cachedScaleX,o.dY=(t.pageY-(o.axisY||0))/d;var l=o.dX,g=o.dY;"x"===e?g=0:"y"===e&&(l=0);var p=o.startLeft+l,h=o.startTop+g;"y"!==e&&(p<i?l=i-o.startLeft:p>a&&(l=a-o.startLeft)),"x"!==e&&(h<n?g=n-o.startTop:h>s&&(g=s-o.startTop)),o.draggerRef&&(o.draggerRef.style.transform="translate("+l+"px, "+g+"px)"),t.stopPropagation()},o.endDrag=function(){o.isDragging&&(o.calcPosition(),o.draggerRef&&(o.draggerRef.style.transform=""),o.props.showDragArea&&o.hideDragArea()),null==o.__moveDisposer||o.__moveDisposer(),o.__moveDisposer=void 0,o.__clickDisposer&&requestAnimationFrame(function(){o.__clickDisposer&&(o.__clickDisposer(),o.__clickDisposer=void 0)}),null==o.__upDisposer||o.__upDisposer(),o.__upDisposer=void 0,null==o.__bodyClassDisposer||o.__bodyClassDisposer(),o.__bodyClassDisposer=void 0,o.isDragging=!1},o.showDragArea=function(){if(o.props.showDragArea&&o.dragAreaRef){var t=o.props.lockAxis,e=o.dragPositionBoundaries,r=e.minX,i=e.maxX,a=e.minY,n=e.maxY,s=o.dragBoxSize;o.dragAreaRef.style.border="1px dashed var(--ohkit-color-primary, #1890ff)",o.dragAreaRef.style.backgroundColor="rgba(173, 216, 230, 0.2)","x"===t?(o.dragAreaRef.style.width=i-r+s.width+"px",o.dragAreaRef.style.height="2px",o.dragAreaRef.style.left=r+"px",o.dragAreaRef.style.top=o.startTop+s.height/2+"px",o.dragAreaRef.style.border="none",o.dragAreaRef.style.backgroundColor="transparent",o.dragAreaRef.style.backgroundImage="linear-gradient(to right, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)",o.dragAreaRef.style.backgroundSize="4px 2px"):"y"===t?(o.dragAreaRef.style.width="2px",o.dragAreaRef.style.height=n-a+s.height+"px",o.dragAreaRef.style.left=o.startLeft+s.width/2+"px",o.dragAreaRef.style.top=a+"px",o.dragAreaRef.style.border="none",o.dragAreaRef.style.backgroundColor="transparent",o.dragAreaRef.style.backgroundImage="linear-gradient(to bottom, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)",o.dragAreaRef.style.backgroundSize="2px 4px"):(o.dragAreaRef.style.width=i-r+s.width+"px",o.dragAreaRef.style.height=n-a+s.height+"px",o.dragAreaRef.style.left=r+"px",o.dragAreaRef.style.top=a+"px"),o.dragAreaRef.style.display="block"}},o.hideDragArea=function(){o.dragAreaRef&&(o.dragAreaRef.style.display="none")},o.calcPosition=function(){var t=o.props.lockAxis,e=o.dragPositionBoundaries,r=e.minX,i=e.maxX,a=e.maxY,n=o.windowSize,s=o.startTop,d=o.startLeft;"y"!==t&&(d+=o.dX),"x"!==t&&(s+=o.dY);var l=Math.min(Math.max(e.minY,s),a),g=Math.min(Math.max(r,d),i),p=n.height-l-o.dragBoxSize.height,h=n.width-g-o.dragBoxSize.width;l===o.state.top&&g===o.state.left&&o.state.bottom===p&&o.state.right===h||o.setState({top:l,left:g,bottom:p,right:h}),o.startTop=l,o.startLeft=g,o.dX=o.dY=0};var i=e.placement,a=e.offsetY,n=void 0===a?20:a,s=e.offsetX,d=void 0===s?20:s,g=(void 0===i?"bottom-right":i).split("-"),p=g[0],h=g[1];return o.state={top:"top"===p?n:void 0,bottom:"bottom"===p?n:void 0,left:"left"===h?d:void 0,right:"right"===h?d:void 0},o}var g,p;p=t,(g=o).prototype=Object.create(p.prototype),g.prototype.constructor=g,n(g,p);var h,f,c=o.prototype;return c.getOtherYKey=function(t){return"top"===t?"bottom":"top"},c.getOtherXKey=function(t){return"left"===t?"right":"left"},c.updatePosition=function(t,e){var r,o=this.getOtherYKey(t),i=this.getOtherXKey(e);this.setState(((r={})[o]=this.dragPositionRang.height-(this.state[t]||0),r[i]=this.dragPositionRang.width-(this.state[e]||0),r))},c.getContainer=function(){var t,e=this.props.positionMode;return"fixed"===(void 0===e?"fixed":e)?(t=this.draggerRef)&&r.findParent(t,function(t){var e=window.getComputedStyle(t),r=e.getPropertyValue("transform"),o=e.getPropertyValue("filter"),i=e.getPropertyValue("perspective");if("none"!==r||"none"!==o||"none"!==i)return!0},{excludeOwn:!0})||document.documentElement:function(t){return t&&r.findParent(t,function(t){if("static"!==window.getComputedStyle(t).getPropertyValue("position"))return!0},{excludeOwn:!0})||document.body}(this.draggerRef)},c.getContainerRect=function(){var t=this.props.positionMode,e="fixed"===(void 0===t?"fixed":t),r=this.getContainer(),o=r.getBoundingClientRect(),i=window.document.scrollingElement||window.document.body,a=r===window.document.body||r===window.document.documentElement;return{width:o.width,height:o.height,left:e&&a?Math.max(o.left,0):o.left+i.scrollLeft,top:e&&a?Math.max(o.top,0):o.top+i.scrollTop,scrollLeft:e&&a?0:r.scrollLeft,scrollTop:e&&a?0:r.scrollTop,scrollerScrollLeft:e&&a?0:i.scrollLeft,scrollerScrollTop:e&&a?0:i.scrollTop}},c.reportStartPosition=function(){if(this.draggerRef){var t=this.draggerRef.getBoundingClientRect(),e=t.top,r=t.left,o=this.getContainerRect(),i=function(t){if(!t)return{scaleX:1,scaleY:1};var e=t.getBoundingClientRect();return{scaleX:t.offsetWidth>0?Math.round(e.width/t.offsetWidth*10)/10:1,scaleY:t.offsetHeight>0?Math.round(e.height/t.offsetHeight*10)/10:1}}(this.draggerRef),a=i.scaleX,n=i.scaleY;this.cachedScaleX=a,this.cachedScaleY=n,this.startTop=(e-o.top+o.scrollerScrollTop)/n+o.scrollTop,this.startLeft=(r-o.left+o.scrollerScrollLeft)/a+o.scrollLeft}},c.componentDidMount=function(){var t=this;this.reportStartPosition(),this.calcPosition(),this.__resizeDisposer=r.addEventListener(window,"resize",function(){t.calcPosition()})},c.componentWillUnmount=function(){var t,e,r,o,i;null==(t=this.__resizeDisposer)||t.call(this),null==(e=this.__bodyClassDisposer)||e.call(this),null==(r=this.__moveDisposer)||r.call(this),null==(o=this.__clickDisposer)||o.call(this),null==(i=this.__upDisposer)||i.call(this)},c.render=function(){var t=this,r=this.props,o=r.className,n=r.zIndex,s=r.children,d=r.showDragArea,g=r.positionMode,p=void 0===g?"fixed":g,h=this.startDrag,f=this.endDrag,c=a({zIndex:n},this.position,{position:p});/*#__PURE__*/return i.default.createElement(Fragment,null,d&&/*#__PURE__*/i.default.createElement("div",{className:l("drag-area"),ref:function(e){t.dragAreaRef=e},style:{display:"none",position:p,backgroundColor:"rgba(173, 216, 230, 0.2)",border:"1px dashed var(--ohkit-color-primary, #1890ff)",pointerEvents:"none",zIndex:(n||9999)-1,boxSizing:"border-box",borderRadius:"none"!==this.props.lockAxis?"2px":"0"}}),/*#__PURE__*/i.default.createElement("div",{className:e.classNames(l("container"),o),style:c,ref:function(e){t.draggerRef=e},onMouseDown:h,onMouseUp:f},s))},h=o,(f=[{key:"windowSize",get:function(){var t=this.getContainer();return{height:t.clientHeight,width:t.clientWidth}}},{key:"dragBoxSize",get:function(){var t=0,e=0;return this.draggerRef&&(t=this.draggerRef.offsetWidth,e=this.draggerRef.offsetHeight),{height:e,width:t}}},{key:"dragPositionBoundaries",get:function(){var t=this.props,e=t.boundsX,r=t.boundsY,o=t.placement,i=this.dragBoxSize,a=this.windowSize,n=(void 0===o?"bottom-right":o).split("-"),s=n[0],d=0,l=a.width-i.width,g=0,p=a.height-i.height;if(e){var h=e[0],f=e[1];if("left"===n[1])void 0!==h&&(d=Math.max(d,h)),void 0!==f&&(l=Math.min(l,f));else if(void 0!==h&&void 0!==f?(d=Math.max(d,a.width-f-i.width),l=Math.min(l,a.width-h-i.width)):void 0!==h?l=Math.min(l,a.width-h-i.width):void 0!==f&&(d=Math.max(d,a.width-f-i.width)),d>l){var c=[l,d];d=c[0],l=c[1]}}if(r){var u=r[0],m=r[1];if("top"===s)void 0!==u&&(g=Math.max(g,u)),void 0!==m&&(p=Math.min(p,m));else if(void 0!==u&&void 0!==m?(g=Math.max(g,a.height-m-i.height),p=Math.min(p,a.height-u-i.height)):void 0!==u?p=Math.min(p,a.height-u-i.height):void 0!==m&&(g=Math.max(g,a.height-m-i.height)),g>p){var v=[p,g];g=v[0],p=v[1]}}return{minX:d,maxX:l,minY:g,maxY:p}}},{key:"dragPositionRang",get:function(){var t=this.dragPositionBoundaries;return{width:t.maxX,height:t.maxY}}},{key:"curPositionKey",get:function(){var t=this.props.placement;return t&&d.includes(t)||(t="bottom-right"),t.split("-")}},{key:"position",get:function(){var t=this.curPositionKey,e=t[0],r=t[1],o={};return void 0!==this.state[e]&&(o[e]=this.state[e]+"px"),void 0!==this.state[r]&&(o[r]=this.state[r]+"px"),o}}])&&function(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,s(o.key),o)}}(h.prototype,f),Object.defineProperty(h,"prototype",{writable:!1}),h}(i.default.Component);g.defaultProps={zIndex:9999,offsetX:20,offsetY:20,placement:"bottom-right",disabled:!1,lockAxis:"none",showDragArea:!1,positionMode:"fixed"},exports.DraggableBox=g,exports.c=l,exports.default=g;
|
|
1
|
+
var e=require("react"),t=require("@ohkit/prefix-classname"),r=require("@ohkit/dom-helper");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/i(e);function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)({}).hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},a.apply(null,arguments)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function n(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}function d(e,t){var r=window.getComputedStyle(e),i=r.getPropertyValue("position"),o=r.getPropertyValue("transform"),a=r.getPropertyValue("filter"),s=r.getPropertyValue("perspective"),n=r.getPropertyValue("contain"),d=r.getPropertyValue("will-change");return t&&"static"!==i||"none"!==o||"none"!==a||"none"!==s||n.includes("paint")||n.includes("layout")||n.includes("strict")||d.includes("transform")||d.includes("perspective")||d.includes("filter")}function l(e,t,r){return Math.min(Math.max(e,t),r)}var p=["top-left","top-right","bottom-left","bottom-right"],h=t.prefixClassname("ohkit-draggable-box__"),c=/*#__PURE__*/function(e){function i(t){var i;(i=e.call(this,t)||this).prePositionMode=void 0,i.preDraggerRef=null,i.container=null,i.draggerRef=null,i.isDragging=!1,i.axisX=void 0,i.axisY=void 0,i.dX=0,i.dY=0,i.startTop=0,i.startLeft=0,i.cachedScaleX=1,i.cachedScaleY=1,i.__moveDisposer=void 0,i.__clickDisposer=void 0,i.__bodyClassDisposer=void 0,i.__upDisposer=void 0,i.__resizeDisposer=void 0,i.dragAreaRef=null,i.enableDrag=function(){i.reportStartPosition(),null==i.__moveDisposer||i.__moveDisposer(),i.__moveDisposer=r.addEventListener(document,"mousemove",function(e){i.__clickDisposer||Math.sqrt(Math.pow(i.dX,2)+Math.pow(i.dY,2))>5&&(i.__clickDisposer=r.addEventListener(document,"click",function(e){e.stopPropagation()},!0),i.__bodyClassDisposer=r.addClass([document.body,i.draggerRef],h("moving"))||void 0,i.props.showDragArea&&i.dragAreaRef&&i.showDragArea()),i.dragging(e)},!0),null==i.__upDisposer||i.__upDisposer(),i.__upDisposer=r.addEventListener(document,"mouseup",function(e){i.endDrag(),e.stopPropagation(),e.preventDefault()},!0)},i.startDrag=function(e){2!==e.nativeEvent.button&&(i.axisX=e.nativeEvent.pageX,i.axisY=e.nativeEvent.pageY,i.props.disabled||i.enableDrag())},i.dragging=function(e){i.isDragging=!0;var t=i.props.lockAxis,r=i.dragPositionBoundaries,o=r.minX,a=r.maxX,s=r.minY,n=r.maxY,d=i.cachedScaleY;i.dX=(e.pageX-(i.axisX||0))/i.cachedScaleX,i.dY=(e.pageY-(i.axisY||0))/d;var l=i.dX,p=i.dY;"x"===t?p=0:"y"===t&&(l=0);var h=i.startLeft+l,c=i.startTop+p;"y"!==t&&(h<o?l=o-i.startLeft:h>a&&(l=a-i.startLeft)),"x"!==t&&(c<s?p=s-i.startTop:c>n&&(p=n-i.startTop)),i.draggerRef&&(i.draggerRef.style.transform="translate("+l+"px, "+p+"px)"),e.stopPropagation()},i.endDrag=function(){i.isDragging&&(i.calcPosition(),i.draggerRef&&(i.draggerRef.style.transform=""),i.props.showDragArea&&i.hideDragArea()),null==i.__moveDisposer||i.__moveDisposer(),i.__moveDisposer=void 0,i.__clickDisposer&&requestAnimationFrame(function(){i.__clickDisposer&&(i.__clickDisposer(),i.__clickDisposer=void 0)}),null==i.__upDisposer||i.__upDisposer(),i.__upDisposer=void 0,null==i.__bodyClassDisposer||i.__bodyClassDisposer(),i.__bodyClassDisposer=void 0,i.isDragging=!1},i.showDragArea=function(){if(i.props.showDragArea&&i.dragAreaRef){var e=i.props.lockAxis,t=i.dragPositionBoundaries,r=t.minX,o=t.maxX,a=t.minY,s=t.maxY,n=i.dragBoxSize;i.dragAreaRef.style.border="1px dashed var(--ohkit-color-primary, #1890ff)",i.dragAreaRef.style.backgroundColor="rgba(173, 216, 230, 0.2)","x"===e?(i.dragAreaRef.style.width=o-r+n.width+"px",i.dragAreaRef.style.height="2px",i.dragAreaRef.style.left=r+"px",i.dragAreaRef.style.top=i.startTop+n.height/2+"px"):"y"===e?(i.dragAreaRef.style.width="2px",i.dragAreaRef.style.height=s-a+n.height+"px",i.dragAreaRef.style.left=i.startLeft+n.width/2+"px",i.dragAreaRef.style.top=a+"px"):(i.dragAreaRef.style.width=o-r+n.width+"px",i.dragAreaRef.style.height=s-a+n.height+"px",i.dragAreaRef.style.left=r+"px",i.dragAreaRef.style.top=a+"px"),i.dragAreaRef.style.display="block"}},i.hideDragArea=function(){i.dragAreaRef&&(i.dragAreaRef.style.display="none")},i.calcPosition=function(){var e=i.props.lockAxis,t=i.dragPositionBoundaries,r=t.minX,o=t.maxX,a=t.minY,s=t.maxY,n=i.getContainerRect(),d=n.height,p=n.width,h=i.startTop,c=i.startLeft;"y"!==e&&(c+=i.dX),"x"!==e&&(h+=i.dY);var g=l(h,a,s),f=l(c,r,o),u=d-g-i.dragBoxSize.height,m=p-f-i.dragBoxSize.width;g===i.state.top&&f===i.state.left&&i.state.bottom===u&&i.state.right===m||i.setState({top:g,left:f,bottom:u,right:m}),i.startTop=g,i.startLeft=f,i.dX=i.dY=0};var o=t.placement,a=t.offsetY,s=void 0===a?20:a,n=t.offsetX,d=void 0===n?20:n,p=(void 0===o?"bottom-right":o).split("-"),c=p[0],g=p[1];return i.state={top:"top"===c?s:void 0,bottom:"bottom"===c?s:void 0,left:"left"===g?d:void 0,right:"right"===g?d:void 0},i}var c,g;g=e,(c=i).prototype=Object.create(g.prototype),c.prototype.constructor=c,s(c,g);var f,u,m=i.prototype;return m.getContainer=function(e){void 0===e&&(e=!0);var t,i=this.props.positionMode,o=void 0===i?"fixed":i;return this.container&&e&&this.prePositionMode===o&&this.preDraggerRef===this.draggerRef||(this.prePositionMode=o,this.preDraggerRef=this.draggerRef,this.container="fixed"===o?(t=this.draggerRef)?r.findParent(t,function(e){return d(e,!1)},{excludeOwn:!0}):document.documentElement:function(e){return e?r.findParent(e,function(e){return d(e,!0)},{excludeOwn:!0}):document.body}(this.draggerRef)),this.container},m.getContainerRect=function(){var e=this.getContainer(!1);if(!e)return{width:window.innerWidth,height:window.innerHeight,left:0,top:0,scrollLeft:0,scrollTop:0,scrollerScrollLeft:0,scrollerScrollTop:0,borderLeftWidth:0,borderTopWidth:0};var t=e.getBoundingClientRect(),r=window.getComputedStyle(e),i=parseFloat(r.borderLeftWidth)||0,o=parseFloat(r.borderTopWidth)||0,a=parseFloat(r.borderRightWidth)||0,s=parseFloat(r.borderBottomWidth)||0;return{width:t.width/this.cachedScaleX-i-a-(e.offsetWidth-e.clientWidth-i-a),height:t.height/this.cachedScaleY-o-s-(e.offsetHeight-e.clientHeight-o-s),left:t.left/this.cachedScaleX,top:t.top/this.cachedScaleY,scrollLeft:e.scrollLeft,scrollTop:e.scrollTop,borderLeftWidth:i,borderTopWidth:o}},m.reportStartPosition=function(){if(this.draggerRef){var e=function(e){if(!e)return{scaleX:1,scaleY:1};var t=e.getBoundingClientRect(),r=1e4;return{scaleX:e.offsetWidth>0?Math.round(t.width/e.offsetWidth*r)/r:1,scaleY:e.offsetHeight>0?Math.round(t.height/e.offsetHeight*r)/r:1}}(this.getContainer()),t=e.scaleY;this.cachedScaleX=e.scaleX,this.cachedScaleY=t;var r=this.draggerRef.getBoundingClientRect(),i=r.top,o=r.left,a=this.getContainerRect();this.startTop=i/t-a.top+a.scrollTop-a.borderTopWidth,this.startLeft=o/t-a.left+a.scrollLeft-a.borderLeftWidth}},m.componentDidMount=function(){var e=this;this.reportStartPosition(),this.calcPosition(),this.__resizeDisposer=r.addEventListener(window,"resize",function(){e.calcPosition()})},m.componentWillUnmount=function(){var e,t,r,i,o;null==(e=this.__resizeDisposer)||e.call(this),null==(t=this.__bodyClassDisposer)||t.call(this),null==(r=this.__moveDisposer)||r.call(this),null==(i=this.__clickDisposer)||i.call(this),null==(o=this.__upDisposer)||o.call(this)},m.render=function(){var e=this,r=this.props,i=r.className,s=r.zIndex,n=r.children,d=r.showDragArea,l=r.positionMode,p=void 0===l?"fixed":l,c=this.startDrag,g=this.endDrag,f=a({zIndex:s},this.position,{position:p});/*#__PURE__*/return o.default.createElement(Fragment,null,d&&/*#__PURE__*/o.default.createElement("div",{className:h("drag-area"),ref:function(t){e.dragAreaRef=t},style:{display:"none",position:p,backgroundColor:"rgba(173, 216, 230, 0.2)",border:"1px dashed var(--ohkit-color-primary, #1890ff)",pointerEvents:"none",zIndex:(s||9999)-1,boxSizing:"border-box",borderRadius:"none"!==this.props.lockAxis?"2px":"0"}}),/*#__PURE__*/o.default.createElement("div",{className:t.classNames(h("container"),i),style:f,ref:function(t){e.draggerRef=t},onMouseDown:c,onMouseUp:g},n))},f=i,(u=[{key:"dragBoxSize",get:function(){var e=0,t=0;return this.draggerRef&&(e=this.draggerRef.offsetWidth,t=this.draggerRef.offsetHeight),{height:t,width:e}}},{key:"dragPositionBoundaries",get:function(){var e=this.props,t=e.boundsX,r=e.boundsY,i=e.placement,o=void 0===i?"bottom-right":i,a=this.dragBoxSize,s=this.getContainerRect(),n=s.width,d=s.height,p=o.split("-"),h=p[0],c=p[1],g={minX:0,maxX:Math.max(n-a.width,0),minY:0,maxY:Math.max(d-a.height,0)},f=g.minX,u=g.maxX,m=g.minY,v=g.maxY;if(t){var x=t[0],y=t[1];"left"===c?(void 0!==x&&(f=Math.max(f,x)),void 0!==y&&(u=Math.min(u,y))):void 0!==x&&void 0!==y?(f=Math.max(f,n-y-a.width),u=Math.min(u,n-x-a.width)):void 0!==x?u=Math.min(u,n-x-a.width):void 0!==y&&(f=Math.max(f,n-y-a.width))}if(r){var _=r[0],b=r[1];"top"===h?(void 0!==_&&(m=Math.max(m,_)),void 0!==b&&(v=Math.min(v,b))):void 0!==_&&void 0!==b?(m=Math.max(m,d-b-a.height),v=Math.min(v,d-_-a.height)):void 0!==_?v=Math.min(v,d-_-a.height):void 0!==b&&(m=Math.max(m,d-b-a.height))}return{minX:f=l(f,g.minX,g.maxX),maxX:u=l(u,f,g.maxX),minY:m=l(m,g.minY,g.maxY),maxY:v=l(v,m,g.maxY)}}},{key:"curPositionKey",get:function(){var e=this.props.placement;return e&&p.includes(e)||(e="bottom-right"),e.split("-")}},{key:"position",get:function(){var e=this.curPositionKey,t=e[0],r=e[1],i={};return void 0!==this.state[t]&&(i[t]=this.state[t]+"px"),void 0!==this.state[r]&&(i[r]=this.state[r]+"px"),i}}])&&function(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,n(i.key),i)}}(f.prototype,u),Object.defineProperty(f,"prototype",{writable:!1}),f}(o.default.Component);c.defaultProps={zIndex:9999,offsetX:20,offsetY:20,placement:"bottom-right",disabled:!1,lockAxis:"none",showDragArea:!1,positionMode:"fixed"},exports.DraggableBox=c,exports.c=h,exports.default=c;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/constants.ts","../src/index.tsx","../src/utils.ts"],"sourcesContent":["\nexport const ValidPlacement = ['top-left', 'top-right', 'bottom-left', 'bottom-right'] as const;\n","import React from 'react';\nimport {\n prefixClassname as p,\n classNames as cx,\n} from \"@ohkit/prefix-classname\";\nimport {addEventListener, addClass} from '@ohkit/dom-helper';\nimport {findFixedPositionParent, findAbsolutePositionParent, getScaleRatio} from './utils';\nimport {ValidPlacement} from './constants';\nimport {DraggableBoxProps, DraggableBoxState} from './type';\n\nimport './style.scss';\n\nexport const c = p(\"ohkit-draggable-box__\");\nexport class DraggableBox extends React.Component<DraggableBoxProps, DraggableBoxState> {\n static defaultProps: Partial<DraggableBoxProps> = {\n zIndex: 9999,\n offsetX: 20,\n offsetY: 20,\n placement: 'bottom-right',\n disabled: false,\n lockAxis: 'none',\n showDragArea: false,\n positionMode: 'fixed',\n };\n\n constructor(props: DraggableBoxProps) {\n super(props);\n \n const { placement = 'bottom-right', offsetY = 20, offsetX = 20 } = props;\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n // 简化状态初始化\n this.state = {\n top: placementY === 'top' ? offsetY : undefined,\n bottom: placementY === 'bottom' ? offsetY : undefined,\n left: placementX === 'left' ? offsetX : undefined,\n right: placementX === 'right' ? offsetX : undefined,\n };\n }\n\n getOtherYKey(yKey: 'top' | 'bottom') {\n return yKey === 'top' ? 'bottom' : 'top';\n }\n\n getOtherXKey(xKey: 'left' | 'right') {\n return xKey === 'left' ? 'right' : 'left';\n }\n\n // TODO:\n updatePosition(yKey: 'top' | 'bottom', xKey: 'left' | 'right') {\n const oYKey = this.getOtherYKey(yKey);\n const oXKey = this.getOtherXKey(xKey);\n this.setState({\n [oYKey]: this.dragPositionRang.height - (this.state[yKey] || 0),\n [oXKey]: this.dragPositionRang.width - (this.state[xKey] || 0),\n });\n }\n /**\n * 获取定位容器\n * 根据 positionMode 返回对应的定位父元素\n */\n private getContainer(): HTMLElement {\n const { positionMode = 'fixed' } = this.props;\n return positionMode === 'fixed' \n ? findFixedPositionParent(this.draggerRef) \n : findAbsolutePositionParent(this.draggerRef);\n }\n\n /**\n * 获取容器的尺寸和位置信息\n */\n private getContainerRect() {\n const { positionMode = 'fixed' } = this.props;\n const isFixed = positionMode === 'fixed';\n const container = this.getContainer();\n const containerRect = container.getBoundingClientRect();\n const rootScrollingElement = window.document.scrollingElement || window.document.body;\n const isRoot = container === window.document.body || container === window.document.documentElement;\n return {\n width: containerRect.width,\n height: containerRect.height,\n left: isFixed && isRoot ? Math.max(containerRect.left, 0) : containerRect.left + rootScrollingElement.scrollLeft,\n top: isFixed && isRoot ? Math.max(containerRect.top, 0) : containerRect.top + rootScrollingElement.scrollTop,\n scrollLeft: isFixed && isRoot ? 0 : container.scrollLeft, // container.scrollLeft,\n scrollTop: isFixed && isRoot ? 0 : container.scrollTop, // container.scrollTop\n scrollerScrollLeft: isFixed && isRoot ? 0 : rootScrollingElement.scrollLeft,\n scrollerScrollTop: isFixed && isRoot ? 0 : rootScrollingElement.scrollTop\n };\n }\n\n get windowSize() {\n const container = this.getContainer();\n const { clientWidth, clientHeight } = container;\n return {\n height: clientHeight,\n width: clientWidth\n };\n }\n\n get dragBoxSize() {\n let width = 0;\n let height = 0;\n if (this.draggerRef) {\n width = this.draggerRef.offsetWidth;\n height = this.draggerRef.offsetHeight;\n }\n return {\n height,\n width\n };\n }\n\n get dragPositionBoundaries() {\n const { boundsX, boundsY, placement = 'bottom-right' } = this.props;\n const dragSize = this.dragBoxSize;\n const windowSize = this.windowSize;\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n // 初始化边界\n let minX = 0;\n let maxX = windowSize.width - dragSize.width;\n let minY = 0;\n let maxY = windowSize.height - dragSize.height;\n\n // 处理X轴边界\n if (boundsX) {\n const [minBound, maxBound] = boundsX;\n \n if (placementX === 'left') {\n // 左边位置:boundsX=[左边最小距离, 左边最大距离]\n if (minBound !== undefined) minX = Math.max(minX, minBound);\n if (maxBound !== undefined) maxX = Math.min(maxX, maxBound);\n } else {\n // 右边位置:boundsX=[右边最小距离, 右边最大距离]\n // 直接使用边界值作为right的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minX = Math.max(minX, windowSize.width - maxBound - dragSize.width);\n maxX = Math.min(maxX, windowSize.width - minBound - dragSize.width);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxX = Math.min(maxX, windowSize.width - minBound - dragSize.width);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minX = Math.max(minX, windowSize.width - maxBound - dragSize.width);\n }\n \n // 确保最小边界不大于最大边界\n if (minX > maxX) {\n [minX, maxX] = [maxX, minX];\n }\n }\n }\n\n // 处理Y轴边界\n if (boundsY) {\n const [minBound, maxBound] = boundsY;\n \n if (placementY === 'top') {\n // 顶部位置:boundsY=[顶边最小距离, 顶边最大距离]\n if (minBound !== undefined) minY = Math.max(minY, minBound);\n if (maxBound !== undefined) maxY = Math.min(maxY, maxBound);\n } else {\n // 底部位置:boundsY=[底边最小距离, 底边最大距离]\n // 直接使用边界值作为bottom的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minY = Math.max(minY, windowSize.height - maxBound - dragSize.height);\n maxY = Math.min(maxY, windowSize.height - minBound - dragSize.height);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxY = Math.min(maxY, windowSize.height - minBound - dragSize.height);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minY = Math.max(minY, windowSize.height - maxBound - dragSize.height);\n }\n \n // 确保最小边界不大于最大边界\n if (minY > maxY) {\n [minY, maxY] = [maxY, minY];\n }\n }\n }\n\n return { minX, maxX, minY, maxY };\n }\n \n // 保持向后兼容\n get dragPositionRang() {\n const { maxX, maxY } = this.dragPositionBoundaries;\n return { width: maxX, height: maxY };\n }\n\n get curPositionKey() {\n let {placement} = this.props;\n if (!placement || !ValidPlacement.includes(placement)) {\n placement = 'bottom-right';\n }\n return placement.split('-') as ['top' | 'bottom', 'left' | 'right']; // [y, x]\n }\n\n get position() {\n const [y, x] = this.curPositionKey;\n const positionStyles: Record<string, string> = {};\n \n // 确保位置值存在且是有效的数字\n if (this.state[y] !== undefined) {\n positionStyles[y] = `${this.state[y]}px`;\n }\n if (this.state[x] !== undefined) {\n positionStyles[x] = `${this.state[x]}px`;\n }\n \n return positionStyles;\n }\n\n draggerRef: HTMLDivElement | null = null;\n\n isDragging = false;\n\n axisX?: number;\n axisY?: number;\n dX = 0;\n dY = 0;\n startTop = 0;\n startLeft = 0;\n\n // 缓存缩放比例,避免在 dragging 中频繁计算\n cachedScaleX = 1;\n cachedScaleY = 1;\n\n __moveDisposer?: () => void;\n __clickDisposer?: () => void;\n __bodyClassDisposer?: () => void;\n __upDisposer?: () => void;\n __resizeDisposer?: () => void;\n\n dragAreaRef: HTMLDivElement | null = null;\n\n reportStartPosition() {\n if (this.draggerRef) {\n const { top, left } = this.draggerRef.getBoundingClientRect();\n const containerRect = this.getContainerRect();\n // console.log(containerRect, 'containerRect');\n \n // 获取缩放比例\n const { scaleX, scaleY } = getScaleRatio(this.draggerRef);\n this.cachedScaleX = scaleX;\n this.cachedScaleY = scaleY;\n \n // 计算相对于容器的位置,并除以缩放比例得到未缩放的坐标\n this.startTop = (top - containerRect.top + containerRect.scrollerScrollTop) / scaleY + containerRect.scrollTop;\n this.startLeft = (left - containerRect.left + containerRect.scrollerScrollLeft) / scaleX + containerRect.scrollLeft;\n }\n }\n\n enableDrag = () => {\n this.reportStartPosition();\n this.__moveDisposer?.();\n this.__moveDisposer = addEventListener(document, 'mousemove', (evt) => {\n // INFO: 移动过程中禁止click事件\n if (!this.__clickDisposer) {\n const moveDistanse = Math.sqrt(Math.pow(this.dX, 2) + Math.pow(this.dY, 2));\n // INFO: 移动超过5px?? 确保用户有真实的移动意愿,而不是手抖~~\n if (moveDistanse > 5) {\n this.__clickDisposer = addEventListener(\n document,\n 'click',\n (evt) => {\n evt.stopPropagation();\n },\n true\n );\n this.__bodyClassDisposer = addClass([document.body, this.draggerRef], c('moving')) || undefined;\n \n // 显示拖拽区域\n if (this.props.showDragArea && this.dragAreaRef) {\n this.showDragArea();\n }\n }\n }\n this.dragging(evt);\n }, true);\n\n this.__upDisposer?.();\n this.__upDisposer = addEventListener(\n document,\n 'mouseup',\n (evt) => {\n this.endDrag();\n evt.stopPropagation();\n evt.preventDefault();\n },\n true\n );\n };\n\n startDrag = (evt: React.MouseEvent<HTMLDivElement>) => {\n // 判断鼠标非右击才继续执行\n if (evt.nativeEvent.button === 2) {\n return;\n }\n this.axisX = evt.nativeEvent.pageX;\n this.axisY = evt.nativeEvent.pageY;\n if (!this.props.disabled) {\n this.enableDrag();\n }\n };\n\n dragging = (evt: MouseEvent) => {\n this.isDragging = true;\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n \n // 使用缓存的缩放比例,避免频繁计算\n const scaleX = this.cachedScaleX;\n const scaleY = this.cachedScaleY;\n \n // 计算原始偏移量(需要除以缩放比例)\n this.dX = (evt.pageX - (this.axisX || 0)) / scaleX;\n this.dY = (evt.pageY - (this.axisY || 0)) / scaleY;\n \n // 应用方向锁定并计算变换值\n let translateX = this.dX;\n let translateY = this.dY;\n \n if (lockAxis === 'x') {\n translateY = 0; // 锁定Y方向\n } else if (lockAxis === 'y') {\n translateX = 0; // 锁定X方向\n }\n \n // 应用边界条件到允许移动的方向\n const potentialLeft = this.startLeft + translateX;\n const potentialTop = this.startTop + translateY;\n \n // X轴边界条件(在允许X轴移动时应用)\n if (lockAxis !== 'y') {\n if (potentialLeft < minX) {\n translateX = minX - this.startLeft;\n } else if (potentialLeft > maxX) {\n translateX = maxX - this.startLeft;\n }\n }\n \n // Y轴边界条件(在允许Y轴移动时应用)\n if (lockAxis !== 'x') {\n if (potentialTop < minY) {\n translateY = minY - this.startTop;\n } else if (potentialTop > maxY) {\n translateY = maxY - this.startTop;\n }\n }\n \n if (this.draggerRef) {\n this.draggerRef.style.transform = `translate(${translateX}px, ${translateY}px)`;\n }\n evt.stopPropagation();\n };\n\n endDrag = () => {\n if (this.isDragging) {\n this.calcPosition();\n if (this.draggerRef) {\n this.draggerRef.style.transform = '';\n }\n \n // 隐藏拖拽区域\n if (this.props.showDragArea) {\n this.hideDragArea();\n }\n }\n\n this.__moveDisposer?.();\n this.__moveDisposer = undefined;\n if (this.__clickDisposer) {\n requestAnimationFrame(() => {\n if (this.__clickDisposer) {\n this.__clickDisposer();\n this.__clickDisposer = undefined;\n }\n });\n }\n this.__upDisposer?.();\n this.__upDisposer = undefined;\n this.__bodyClassDisposer?.();\n this.__bodyClassDisposer = undefined;\n\n this.isDragging = false;\n };\n\n showDragArea = () => {\n if (!this.props.showDragArea || !this.dragAreaRef) return;\n \n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const dragSize = this.dragBoxSize;\n \n // 重置样式\n this.dragAreaRef.style.border = '1px dashed var(--ohkit-color-primary, #1890ff)';\n this.dragAreaRef.style.backgroundColor = 'rgba(173, 216, 230, 0.2)'; // 淡透蓝色\n \n if (lockAxis === 'x') {\n // 锁定Y方向,显示为水平虚线区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = '2px'; // 更细的虚线高度\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${this.startTop + dragSize.height / 2}px`;\n this.dragAreaRef.style.border = 'none';\n this.dragAreaRef.style.backgroundColor = 'transparent'; // 透明背景\n this.dragAreaRef.style.backgroundImage = 'linear-gradient(to right, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)';\n this.dragAreaRef.style.backgroundSize = '4px 2px'; // 虚线模式\n } else if (lockAxis === 'y') {\n // 锁定X方向,显示为垂直虚线区域\n this.dragAreaRef.style.width = '2px'; // 更细的虚线宽度\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${this.startLeft + dragSize.width / 2}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n this.dragAreaRef.style.border = 'none';\n this.dragAreaRef.style.backgroundColor = 'transparent'; // 透明背景\n this.dragAreaRef.style.backgroundImage = 'linear-gradient(to bottom, var(--ohkit-color-primary, #1890ff) 50%, transparent 50%)';\n this.dragAreaRef.style.backgroundSize = '2px 4px'; // 虚线模式\n } else {\n // 自由拖拽,显示完整区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n }\n \n this.dragAreaRef.style.display = 'block';\n };\n\n hideDragArea = () => {\n if (this.dragAreaRef) {\n this.dragAreaRef.style.display = 'none';\n }\n };\n calcPosition = () => {\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const containerSize = this.windowSize;\n \n // 计算新的位置\n let newTop = this.startTop;\n let newLeft = this.startLeft;\n \n if (lockAxis !== 'y') {\n newLeft += this.dX;\n }\n if (lockAxis !== 'x') {\n newTop += this.dY;\n }\n \n // 应用边界限制\n const realTop = Math.min(Math.max(minY, newTop), maxY);\n const realLeft = Math.min(Math.max(minX, newLeft), maxX);\n const realBottom = containerSize.height - realTop - this.dragBoxSize.height;\n const realRight = containerSize.width - realLeft - this.dragBoxSize.width;\n if (realTop !== this.state.top || realLeft !== this.state.left || this.state.bottom !== realBottom || this.state.right !== realRight) {\n // console.log(minY, maxY, this.startTop, this.dY, newTop, realTop, 'calcPosition y');\n // console.log(minX, maxX, this.startLeft, this.dX, newLeft, realLeft, 'calcPosition x');\n this.setState({\n top: realTop,\n left: realLeft,\n bottom: realBottom,\n right: realRight\n });\n }\n this.startTop = realTop;\n this.startLeft = realLeft;\n this.dX = this.dY = 0;\n };\n\n\n componentDidMount() {\n // 检查初始位置是否在边界范围内,如果不在则修正\n this.reportStartPosition();\n this.calcPosition();\n \n this.__resizeDisposer = addEventListener(window, 'resize', () => {\n this.calcPosition();\n });\n }\n\n componentWillUnmount() {\n this.__resizeDisposer?.();\n this.__bodyClassDisposer?.();\n this.__moveDisposer?.();\n this.__clickDisposer?.();\n this.__upDisposer?.();\n }\n\n render() {\n const { className, zIndex, children, showDragArea, positionMode = 'fixed' } = this.props;\n const { startDrag, endDrag } = this;\n const stl = {\n zIndex,\n ...this.position,\n position: positionMode\n };\n return (\n <>\n {showDragArea && (\n <div\n className={c('drag-area')}\n ref={(r) => {\n this.dragAreaRef = r;\n }}\n style={{\n display: 'none',\n position: positionMode,\n backgroundColor: 'rgba(173, 216, 230, 0.2)', // 淡透蓝色\n border: '1px dashed var(--ohkit-color-primary, #1890ff)',\n pointerEvents: 'none',\n zIndex: (zIndex || 9999) - 1,\n boxSizing: 'border-box',\n borderRadius: this.props.lockAxis !== 'none' ? '2px' : '0',\n }}\n />\n )}\n <div\n className={cx(c('container'), className)}\n style={stl}\n ref={(r) => {\n this.draggerRef = r;\n }}\n onMouseDown={startDrag}\n onMouseUp={endDrag}\n >\n {children}\n </div>\n </>\n );\n }\n}\n\nexport default DraggableBox;","import {findParent} from '@ohkit/dom-helper';\n\n/**\n * 查找影响 fixed 定位的父元素\n * 当父元素有 transform/filter/perspective 等属性时,fixed 定位会相对于该父元素\n */\nexport function findFixedPositionParent(dom?: HTMLElement | null): HTMLElement {\n if (!dom) {\n return document.documentElement;\n }\n const fixedPositionParent = findParent(dom, (parent) => {\n const style = window.getComputedStyle(parent);\n const transform = style.getPropertyValue('transform');\n const filter = style.getPropertyValue('filter');\n const perspective = style.getPropertyValue('perspective');\n \n // 检查是否有影响 fixed 定位的属性\n if (transform !== 'none' || filter !== 'none' || perspective !== 'none') {\n return true;\n }\n }, {excludeOwn: true}) || document.documentElement; // 没有找到,返回 window(通过 document.documentElement)\n return fixedPositionParent;\n}\n\n/**\n * 查找 absolute 定位的父元素\n * 查找最近的 position 不为 static 的元素\n */\nexport function findAbsolutePositionParent(dom?: HTMLElement | null): HTMLElement {\n if (!dom) {\n return document.body;\n }\n return findParent(dom, (parent) => {\n const style = window.getComputedStyle(parent);\n const position = style.getPropertyValue('position');\n if (position !== 'static') {\n return true;\n }\n }, {excludeOwn: true}) || document.body;\n}\n\n/**\n * 获取容器的缩放比例\n * 通过比较元素的实际尺寸和 getBoundingClientRect 返回的尺寸来计算缩放比例\n */\nexport function getScaleRatio(dom?: HTMLElement | null): { scaleX: number; scaleY: number } {\n if (!dom) {\n return { scaleX: 1, scaleY: 1 };\n }\n // 通过比较 offsetWidth 和 getBoundingClientRect().width 来获取缩放比例\n const rect = dom.getBoundingClientRect();\n // 扩大10倍进行计算,避免浮点数精度问题\n const scaleX = dom.offsetWidth > 0 ? Math.round(rect.width / dom.offsetWidth * 10) / 10 : 1;\n const scaleY = dom.offsetHeight > 0 ? Math.round(rect.height / dom.offsetHeight * 10) / 10 : 1;\n // console.log('scaleX', scaleX, 'scaleY', scaleY);\n return { scaleX, scaleY };\n}\n"],"names":["ValidPlacement","c","p","prefixClassname","DraggableBox","_React$Component","props","_this","call","this","draggerRef","isDragging","axisX","axisY","dX","dY","startTop","startLeft","cachedScaleX","cachedScaleY","__moveDisposer","__clickDisposer","__bodyClassDisposer","__upDisposer","__resizeDisposer","dragAreaRef","enableDrag","reportStartPosition","addEventListener","document","evt","Math","sqrt","pow","stopPropagation","addClass","body","undefined","showDragArea","dragging","endDrag","preventDefault","startDrag","nativeEvent","button","pageX","pageY","disabled","lockAxis","_this$dragPositionBou","dragPositionBoundaries","minX","maxX","minY","maxY","scaleY","translateX","translateY","potentialLeft","potentialTop","style","transform","calcPosition","hideDragArea","requestAnimationFrame","_this$dragPositionBou2","dragSize","dragBoxSize","border","backgroundColor","width","height","left","top","backgroundImage","backgroundSize","display","_this$dragPositionBou3","containerSize","windowSize","newTop","newLeft","realTop","min","max","realLeft","realBottom","realRight","state","bottom","right","setState","_props$placement","placement","_props$offsetY","offsetY","_props$offsetX","offsetX","_placement$split","split","placementY","placementX","_proto","prototype","getOtherYKey","yKey","getOtherXKey","xKey","updatePosition","_this$setState","oYKey","oXKey","dragPositionRang","getContainer","dom","_this$props$positionM","positionMode","findParent","parent","window","getComputedStyle","getPropertyValue","filter","perspective","excludeOwn","documentElement","findAbsolutePositionParent","getContainerRect","_this$props$positionM2","isFixed","container","containerRect","getBoundingClientRect","rootScrollingElement","scrollingElement","isRoot","scrollLeft","scrollTop","scrollerScrollLeft","scrollerScrollTop","_this$draggerRef$getB","_getScaleRatio","scaleX","rect","offsetWidth","round","offsetHeight","getScaleRatio","componentDidMount","_this2","componentWillUnmount","_this$__resizeDispose","_this$__bodyClassDisp","_this$__moveDisposer","_this$__clickDisposer","_this$__upDisposer","render","_this3","_this$props","className","zIndex","children","_this$props$positionM3","stl","_extends","position","React","createElement","Fragment","ref","r","pointerEvents","boxSizing","borderRadius","cx","onMouseDown","onMouseUp","key","get","clientHeight","clientWidth","_this$props2","boundsX","boundsY","_this$props2$placemen","_placement$split2","minBound","maxBound","_ref","_ref2","_this$dragPositionBou4","includes","_this$curPositionKey","curPositionKey","y","x","positionStyles","Component","defaultProps"],"mappings":"2yBACa,IAAAA,EAAiB,CAAC,WAAY,YAAa,cAAe,gBCW1DC,EAAIC,EAACC,gBAAC,yBACNC,eAAaC,SAAAA,GAYtB,SAAAD,EAAYE,GAAwB,IAAAC,GAChCA,EAAAF,EAAAG,KAAAC,KAAMH,UA4LVI,WAAoC,KAAIH,EAExCI,YAAa,EAAKJ,EAElBK,aAAKL,EACLM,WAAKN,EAAAA,EACLO,GAAK,EAACP,EACNQ,GAAK,EAACR,EACNS,SAAW,EAACT,EACZU,UAAY,EAACV,EAGbW,aAAe,EAACX,EAChBY,aAAe,EAACZ,EAEhBa,sBAAcb,EACdc,qBAAed,EAAAA,EACfe,yBAAmB,EAAAf,EACnBgB,kBAAYhB,EAAAA,EACZiB,wBAAgBjB,EAEhBkB,YAAqC,KAAIlB,EAmBzCmB,WAAa,WACTnB,EAAKoB,sBACc,MAAnBpB,EAAKa,gBAALb,EAAKa,iBACLb,EAAKa,eAAiBQ,EAAAA,iBAAiBC,SAAU,YAAa,SAACC,GAEtDvB,EAAKc,iBACeU,KAAKC,KAAKD,KAAKE,IAAI1B,EAAKO,GAAI,GAAKiB,KAAK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A,EAAUM,MAAM,IAC3B,GAAC8E,CAAAA,eAAAC,IAED,WACI,IAAAc,EAAevL,KAAKwL,eAAbC,EAACF,EAAEG,GAAAA,EAACH,EAAA,GACLI,EAAyC,CAAA,EAU/C,YAPsB/J,IAAlB5B,KAAK+E,MAAM0G,KACXE,EAAeF,GAAQzL,KAAK+E,MAAM0G,cAEhB7J,IAAlB5B,KAAK+E,MAAM2G,KACXC,EAAeD,GAAQ1L,KAAK+E,MAAM2G,GACrC,MAEMC,CACX,iPAvM8B9B,CAARjK,CAAQiK,EAAAA,QAAM+B,WAA3BjM,EACFkM,aAA2C,CAC9CtC,OAAQ,KACR/D,QAAS,GACTF,QAAS,GACTF,UAAW,eACX9C,UAAU,EACVC,SAAU,OACVV,cAAc,EACd8E,aAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/constants.ts","../src/index.tsx"],"sourcesContent":["import {findParent} from '@ohkit/dom-helper';\n\n/**\n * 检查元素是否创建了新的定位上下文(包含块)\n * @param element 要检查的元素\n * @param includePosition 是否检查position属性(absolute/relative/fixed)\n */\nexport function isPositioningContextCreator(element: HTMLElement, includePosition: boolean): boolean {\n const style = window.getComputedStyle(element);\n const position = style.getPropertyValue('position');\n const transform = style.getPropertyValue('transform');\n const filter = style.getPropertyValue('filter');\n const perspective = style.getPropertyValue('perspective');\n const contain = style.getPropertyValue('contain');\n const willChange = style.getPropertyValue('will-change');\n \n return (includePosition && position !== 'static') || \n transform !== 'none' || \n filter !== 'none' || \n perspective !== 'none' ||\n contain.includes('paint') ||\n contain.includes('layout') ||\n contain.includes('strict') ||\n willChange.includes('transform') ||\n willChange.includes('perspective') ||\n willChange.includes('filter');\n}\n\n/**\n * 查找影响 fixed 定位的父元素\n * 当父元素有 transform/filter/perspective/contain/will-change 等属性时,fixed 定位会相对于该父元素\n */\nexport function findFixedPositionParent(dom?: HTMLElement | null) {\n if (!dom) {\n return document.documentElement;\n }\n const fixedPositionParent = findParent(dom, (parent) => {\n return isPositioningContextCreator(parent, false);\n }, {excludeOwn: true}); // 没有找到,返回 window(通过 document.documentElement)\n return fixedPositionParent;\n}\n\n/**\n * 查找 absolute 定位的父元素\n * 查找最近的包含块创建者,包含所有可能影响absolute定位的属性\n */\nexport function findAbsolutePositionParent(dom?: HTMLElement | null) {\n if (!dom) {\n return document.body;\n }\n return findParent(dom, (parent) => {\n return isPositioningContextCreator(parent, true);\n }, {excludeOwn: true});\n}\n\n/**\n * 获取容器的缩放比例\n * 通过比较元素的实际尺寸和 getBoundingClientRect 返回的尺寸来计算缩放比例\n */\nexport function getScaleRatio(dom?: HTMLElement | null): { scaleX: number; scaleY: number } {\n if (!dom) {\n return { scaleX: 1, scaleY: 1 };\n }\n // 通过比较 offsetWidth 和 getBoundingClientRect().width 来获取缩放比例\n const rect = dom.getBoundingClientRect();\n let scaleX = 1;\n let scaleY = 1;\n // 扩大{magnification}倍进行计算, 相当于保留小数点后4位\n const magnification = 10000;\n scaleX = dom.offsetWidth > 0 ? Math.round(rect.width / dom.offsetWidth * magnification) / magnification : 1;\n scaleY = dom.offsetHeight > 0 ? Math.round(rect.height / dom.offsetHeight * magnification) / magnification : 1;\n // console.log('rect.width dom.offsetWidth', rect.width, dom.offsetWidth);\n // console.log('rect.height dom.offsetHeight', rect.height, dom.offsetHeight);\n // console.log('scaleX', scaleX, 'scaleY', scaleY);\n return { scaleX, scaleY };\n}\n\n/**\n * 限制数值在指定范围内\n * \n * @param value 要限制的数值\n * @param min 最小值\n * @param max 最大值\n * @returns 限制后的数值,确保在 [min, max] 范围内\n */\nexport function clamp(value: number, min: number, max: number) {\n return Math.min(Math.max(value, min), max);\n}\n","\nexport const ValidPlacement = ['top-left', 'top-right', 'bottom-left', 'bottom-right'] as const;\n","import React from 'react';\nimport {\n prefixClassname as p,\n classNames as cx,\n} from \"@ohkit/prefix-classname\";\nimport {addEventListener, addClass} from '@ohkit/dom-helper';\nimport {findFixedPositionParent, findAbsolutePositionParent, getScaleRatio, clamp} from './utils';\nimport {ValidPlacement} from './constants';\nimport {DraggableBoxProps, DraggableBoxState} from './type';\n\nimport './style.scss';\n\nexport const c = p(\"ohkit-draggable-box__\");\nexport class DraggableBox extends React.Component<DraggableBoxProps, DraggableBoxState> {\n static defaultProps: Partial<DraggableBoxProps> = {\n zIndex: 9999,\n offsetX: 20,\n offsetY: 20,\n placement: 'bottom-right',\n disabled: false,\n lockAxis: 'none',\n showDragArea: false,\n positionMode: 'fixed',\n };\n\n constructor(props: DraggableBoxProps) {\n super(props);\n \n const { placement = 'bottom-right', offsetY = 20, offsetX = 20 } = props;\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n // 简化状态初始化\n this.state = {\n top: placementY === 'top' ? offsetY : undefined,\n bottom: placementY === 'bottom' ? offsetY : undefined,\n left: placementX === 'left' ? offsetX : undefined,\n right: placementX === 'right' ? offsetX : undefined,\n };\n }\n\n private prePositionMode: DraggableBoxProps['positionMode'];\n private preDraggerRef: HTMLElement | null = null;\n private container: HTMLElement | null = null;\n /**\n * 获取定位容器\n * 根据 positionMode 返回对应的定位父元素\n */\n private getContainer(useCache = true) {\n const { positionMode = 'fixed' } = this.props;\n if (!this.container || !useCache || this.prePositionMode !== positionMode || this.preDraggerRef !== this.draggerRef) {\n this.prePositionMode = positionMode;\n this.preDraggerRef = this.draggerRef;\n this.container = positionMode === 'fixed' \n ? findFixedPositionParent(this.draggerRef) \n : findAbsolutePositionParent(this.draggerRef);\n }\n return this.container;\n }\n\n /**\n * 获取容器的尺寸和位置信息\n */\n private getContainerRect() {\n const container = this.getContainer(false);\n if (!container) {\n return {\n width: window.innerWidth,\n height: window.innerHeight,\n left: 0,\n top: 0,\n scrollLeft: 0,\n scrollTop: 0,\n scrollerScrollLeft: 0,\n scrollerScrollTop: 0,\n borderLeftWidth: 0,\n borderTopWidth: 0\n };\n }\n const containerRect = container.getBoundingClientRect();\n \n // 获取容器的border宽度(仅 top, left 对坐标计算有影响)\n const containerStyle = window.getComputedStyle(container);\n const borderLeftWidth = parseFloat(containerStyle.borderLeftWidth) || 0;\n const borderTopWidth = parseFloat(containerStyle.borderTopWidth) || 0;\n const borderRightWidth = parseFloat(containerStyle.borderRightWidth) || 0;\n const borderBottomWidth = parseFloat(containerStyle.borderBottomWidth) || 0;\n const yScrollerWidth = container.offsetWidth - container.clientWidth - borderLeftWidth - borderRightWidth;\n const xScrollerHeight = container.offsetHeight - container.clientHeight - borderTopWidth - borderBottomWidth;\n // console.log('yScrollerWidth, xScrollerHeight', yScrollerWidth, xScrollerHeight);\n\n return {\n width: containerRect.width / this.cachedScaleX - borderLeftWidth - borderRightWidth - yScrollerWidth,\n height: containerRect.height / this.cachedScaleY - borderTopWidth - borderBottomWidth - xScrollerHeight,\n left: containerRect.left / this.cachedScaleX,\n top: containerRect.top / this.cachedScaleY,\n scrollLeft: container.scrollLeft,\n scrollTop: container.scrollTop,\n borderLeftWidth: borderLeftWidth,\n borderTopWidth: borderTopWidth,\n };\n }\n\n get dragBoxSize() {\n let width = 0;\n let height = 0;\n if (this.draggerRef) {\n width = this.draggerRef.offsetWidth;\n height = this.draggerRef.offsetHeight;\n }\n return {\n height,\n width\n };\n }\n\n get dragPositionBoundaries() {\n const { boundsX, boundsY, placement = 'bottom-right' } = this.props;\n const dragSize = this.dragBoxSize;\n const {width: containerWidth, height: containerHeight} = this.getContainerRect();\n const [placementY, placementX] = placement.split('-') as ['top' | 'bottom', 'left' | 'right'];\n \n const defaultBounds = {\n minX: 0,\n maxX: Math.max(containerWidth - dragSize.width, 0),\n minY: 0,\n maxY: Math.max(containerHeight- dragSize.height, 0),\n };\n // 初始化边界\n let {minX, maxX, minY, maxY} = defaultBounds\n\n // 处理X轴边界\n if (boundsX) {\n const [minBound, maxBound] = boundsX;\n if (placementX === 'left') {\n // 左边位置:boundsX=[左边最小距离, 左边最大距离]\n if (minBound !== undefined) minX = Math.max(minX, minBound);\n if (maxBound !== undefined) maxX = Math.min(maxX, maxBound);\n } else {\n // 右边位置:boundsX=[右边最小距离, 右边最大距离]\n // 直接使用边界值作为right的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minX = Math.max(minX, containerWidth - maxBound - dragSize.width);\n maxX = Math.min(maxX, containerWidth - minBound - dragSize.width);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxX = Math.min(maxX, containerWidth - minBound - dragSize.width);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minX = Math.max(minX, containerWidth - maxBound - dragSize.width);\n }\n }\n }\n\n // 处理Y轴边界\n if (boundsY) {\n const [minBound, maxBound] = boundsY;\n \n if (placementY === 'top') {\n // 顶部位置:boundsY=[顶边最小距离, 顶边最大距离]\n if (minBound !== undefined) minY = Math.max(minY, minBound);\n if (maxBound !== undefined) maxY = Math.min(maxY, maxBound);\n } else {\n // 底部位置:boundsY=[底边最小距离, 底边最大距离]\n // 直接使用边界值作为bottom的限制\n if (minBound !== undefined && maxBound !== undefined) {\n minY = Math.max(minY, containerHeight - maxBound - dragSize.height);\n maxY = Math.min(maxY, containerHeight - minBound - dragSize.height);\n } else if (minBound !== undefined) {\n // 只有minBound:设置最大边界,最小边界保持默认\n maxY = Math.min(maxY, containerHeight - minBound - dragSize.height);\n } else if (maxBound !== undefined) {\n // 只有maxBound:设置最小边界,最大边界保持默认\n minY = Math.max(minY, containerHeight - maxBound - dragSize.height);\n }\n }\n }\n // 确保各个边界值在默认范围内\n minX = clamp(minX, defaultBounds.minX, defaultBounds.maxX);\n maxX = clamp(maxX, minX, defaultBounds.maxX);\n minY = clamp(minY, defaultBounds.minY, defaultBounds.maxY);\n maxY = clamp(maxY, minY, defaultBounds.maxY);\n\n return { minX, maxX, minY, maxY };\n }\n\n get curPositionKey() {\n let {placement} = this.props;\n if (!placement || !ValidPlacement.includes(placement)) {\n placement = 'bottom-right';\n }\n return placement.split('-') as ['top' | 'bottom', 'left' | 'right']; // [y, x]\n }\n\n get position() {\n const [y, x] = this.curPositionKey;\n const positionStyles: Record<string, string> = {};\n \n // 确保位置值存在且是有效的数字\n if (this.state[y] !== undefined) {\n positionStyles[y] = `${this.state[y]}px`;\n }\n if (this.state[x] !== undefined) {\n positionStyles[x] = `${this.state[x]}px`;\n }\n \n return positionStyles;\n }\n\n draggerRef: HTMLDivElement | null = null;\n\n isDragging = false;\n\n axisX?: number;\n axisY?: number;\n dX = 0;\n dY = 0;\n startTop = 0;\n startLeft = 0;\n\n // 缓存缩放比例,避免在 dragging 中频繁计算\n cachedScaleX = 1;\n cachedScaleY = 1;\n\n __moveDisposer?: () => void;\n __clickDisposer?: () => void;\n __bodyClassDisposer?: () => void;\n __upDisposer?: () => void;\n __resizeDisposer?: () => void;\n\n dragAreaRef: HTMLDivElement | null = null;\n\n reportStartPosition() {\n if (this.draggerRef) {\n // 获取缩放比例\n const { scaleX, scaleY } = getScaleRatio(this.getContainer());\n this.cachedScaleX = scaleX;\n this.cachedScaleY = scaleY;\n const { top, left } = this.draggerRef.getBoundingClientRect();\n const containerRect = this.getContainerRect();\n // console.log(containerRect, 'containerRect');\n \n // 计算相对于容器的位置,并除以缩放比例得到未缩放的坐标\n this.startTop = top / scaleY - containerRect.top + containerRect.scrollTop - containerRect.borderTopWidth;\n this.startLeft = left / scaleY - containerRect.left + containerRect.scrollLeft - containerRect.borderLeftWidth;\n }\n }\n\n enableDrag = () => {\n this.reportStartPosition();\n this.__moveDisposer?.();\n this.__moveDisposer = addEventListener(document, 'mousemove', (evt) => {\n // INFO: 移动过程中禁止click事件\n if (!this.__clickDisposer) {\n const moveDistanse = Math.sqrt(Math.pow(this.dX, 2) + Math.pow(this.dY, 2));\n // INFO: 移动超过5px?? 确保用户有真实的移动意愿,而不是手抖~~\n if (moveDistanse > 5) {\n this.__clickDisposer = addEventListener(\n document,\n 'click',\n (evt) => {\n evt.stopPropagation();\n },\n true\n );\n this.__bodyClassDisposer = addClass([document.body, this.draggerRef], c('moving')) || undefined;\n \n // 显示拖拽区域\n if (this.props.showDragArea && this.dragAreaRef) {\n this.showDragArea();\n }\n }\n }\n this.dragging(evt);\n }, true);\n\n this.__upDisposer?.();\n this.__upDisposer = addEventListener(\n document,\n 'mouseup',\n (evt) => {\n this.endDrag();\n evt.stopPropagation();\n evt.preventDefault();\n },\n true\n );\n };\n\n startDrag = (evt: React.MouseEvent<HTMLDivElement>) => {\n // 判断鼠标非右击才继续执行\n if (evt.nativeEvent.button === 2) {\n return;\n }\n this.axisX = evt.nativeEvent.pageX;\n this.axisY = evt.nativeEvent.pageY;\n if (!this.props.disabled) {\n this.enableDrag();\n }\n };\n\n dragging = (evt: MouseEvent) => {\n this.isDragging = true;\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n \n // 使用缓存的缩放比例,避免频繁计算\n const scaleX = this.cachedScaleX;\n const scaleY = this.cachedScaleY;\n \n // 计算原始偏移量(需要除以缩放比例)\n this.dX = (evt.pageX - (this.axisX || 0)) / scaleX;\n this.dY = (evt.pageY - (this.axisY || 0)) / scaleY;\n \n // 应用方向锁定并计算变换值\n let translateX = this.dX;\n let translateY = this.dY;\n \n if (lockAxis === 'x') {\n translateY = 0; // 锁定Y方向\n } else if (lockAxis === 'y') {\n translateX = 0; // 锁定X方向\n }\n \n // 应用边界条件到允许移动的方向\n const potentialLeft = this.startLeft + translateX;\n const potentialTop = this.startTop + translateY;\n \n // X轴边界条件(在允许X轴移动时应用)\n if (lockAxis !== 'y') {\n if (potentialLeft < minX) {\n translateX = minX - this.startLeft;\n } else if (potentialLeft > maxX) {\n translateX = maxX - this.startLeft;\n }\n }\n \n // Y轴边界条件(在允许Y轴移动时应用)\n if (lockAxis !== 'x') {\n if (potentialTop < minY) {\n translateY = minY - this.startTop;\n } else if (potentialTop > maxY) {\n translateY = maxY - this.startTop;\n }\n }\n \n if (this.draggerRef) {\n this.draggerRef.style.transform = `translate(${translateX}px, ${translateY}px)`;\n }\n evt.stopPropagation();\n };\n\n endDrag = () => {\n if (this.isDragging) {\n this.calcPosition();\n if (this.draggerRef) {\n this.draggerRef.style.transform = '';\n }\n \n // 隐藏拖拽区域\n if (this.props.showDragArea) {\n this.hideDragArea();\n }\n }\n\n this.__moveDisposer?.();\n this.__moveDisposer = undefined;\n if (this.__clickDisposer) {\n requestAnimationFrame(() => {\n if (this.__clickDisposer) {\n this.__clickDisposer();\n this.__clickDisposer = undefined;\n }\n });\n }\n this.__upDisposer?.();\n this.__upDisposer = undefined;\n this.__bodyClassDisposer?.();\n this.__bodyClassDisposer = undefined;\n\n this.isDragging = false;\n };\n\n showDragArea = () => {\n if (!this.props.showDragArea || !this.dragAreaRef) return;\n \n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const dragSize = this.dragBoxSize;\n \n // 重置样式\n this.dragAreaRef.style.border = '1px dashed var(--ohkit-color-primary, #1890ff)';\n this.dragAreaRef.style.backgroundColor = 'rgba(173, 216, 230, 0.2)'; // 淡透蓝色\n \n if (lockAxis === 'x') {\n // 锁定Y方向,显示为水平虚线区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = '2px'; // 更细的虚线高度\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${this.startTop + dragSize.height / 2}px`;\n } else if (lockAxis === 'y') {\n // 锁定X方向,显示为垂直虚线区域\n this.dragAreaRef.style.width = '2px'; // 更细的虚线宽度\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${this.startLeft + dragSize.width / 2}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n } else {\n // 自由拖拽,显示完整区域\n this.dragAreaRef.style.width = `${maxX - minX + dragSize.width}px`;\n this.dragAreaRef.style.height = `${maxY - minY + dragSize.height}px`;\n this.dragAreaRef.style.left = `${minX}px`;\n this.dragAreaRef.style.top = `${minY}px`;\n }\n \n this.dragAreaRef.style.display = 'block';\n };\n\n hideDragArea = () => {\n if (this.dragAreaRef) {\n this.dragAreaRef.style.display = 'none';\n }\n };\n calcPosition = () => {\n const { lockAxis } = this.props;\n const { minX, maxX, minY, maxY } = this.dragPositionBoundaries;\n const {height, width} = this.getContainerRect();\n \n // 计算新的位置\n let newTop = this.startTop;\n let newLeft = this.startLeft;\n \n if (lockAxis !== 'y') {\n newLeft += this.dX;\n }\n if (lockAxis !== 'x') {\n newTop += this.dY;\n }\n \n // 应用边界限制\n const realTop = clamp(newTop, minY, maxY);\n const realLeft = clamp(newLeft, minX, maxX);\n const realBottom = height - realTop - this.dragBoxSize.height;\n const realRight = width - realLeft - this.dragBoxSize.width;\n if (realTop !== this.state.top || realLeft !== this.state.left || this.state.bottom !== realBottom || this.state.right !== realRight) {\n // console.log(minY, maxY, this.startTop, this.dY, newTop, realTop, 'minY, maxY, this.startTop, this.dY, newTop, realTop --- calcPosition y');\n // console.log(minX, maxX, this.startLeft, this.dX, newLeft, realLeft, 'minX, maxX, this.startLeft, this.dX, newLeft, realLeft ---calcPosition x');\n this.setState({\n top: realTop,\n left: realLeft,\n bottom: realBottom,\n right: realRight\n });\n }\n this.startTop = realTop;\n this.startLeft = realLeft;\n this.dX = this.dY = 0;\n };\n\n\n componentDidMount() {\n // 检查初始位置是否在边界范围内,如果不在则修正\n this.reportStartPosition();\n this.calcPosition();\n \n this.__resizeDisposer = addEventListener(window, 'resize', () => {\n this.calcPosition();\n });\n }\n\n componentWillUnmount() {\n this.__resizeDisposer?.();\n this.__bodyClassDisposer?.();\n this.__moveDisposer?.();\n this.__clickDisposer?.();\n this.__upDisposer?.();\n }\n\n render() {\n const { className, zIndex, children, showDragArea, positionMode = 'fixed' } = this.props;\n const { startDrag, endDrag } = this;\n const stl = {\n zIndex,\n ...this.position,\n position: positionMode\n };\n return (\n <>\n {showDragArea && (\n <div\n className={c('drag-area')}\n ref={(r) => {\n this.dragAreaRef = r;\n }}\n style={{\n display: 'none',\n position: positionMode,\n backgroundColor: 'rgba(173, 216, 230, 0.2)', // 淡透蓝色\n border: '1px dashed var(--ohkit-color-primary, #1890ff)',\n pointerEvents: 'none',\n zIndex: (zIndex || 9999) - 1,\n boxSizing: 'border-box',\n borderRadius: this.props.lockAxis !== 'none' ? '2px' : '0',\n }}\n />\n )}\n <div\n className={cx(c('container'), className)}\n style={stl}\n ref={(r) => {\n this.draggerRef = r;\n }}\n onMouseDown={startDrag}\n onMouseUp={endDrag}\n >\n {children}\n </div>\n </>\n );\n }\n}\n\nexport default DraggableBox;"],"names":["isPositioningContextCreator","element","includePosition","style","window","getComputedStyle","position","getPropertyValue","transform","filter","perspective","contain","willChange","includes","clamp","value","min","max","Math","ValidPlacement","c","p","prefixClassname","DraggableBox","_React$Component","props","_this","call","this","prePositionMode","preDraggerRef","container","draggerRef","isDragging","axisX","axisY","dX","dY","startTop","startLeft","cachedScaleX","cachedScaleY","__moveDisposer","__clickDisposer","__bodyClassDisposer","__upDisposer","__resizeDisposer","dragAreaRef","enableDrag","reportStartPosition","addEventListener","document","evt","sqrt","pow","stopPropagation","addClass","body","undefined","showDragArea","dragging","endDrag","preventDefault","startDrag","nativeEvent","button","pageX","pageY","disabled","lockAxis","_this$dragPositionBou","dragPositionBoundaries","minX","maxX","minY","maxY","scaleY","translateX","translateY","potentialLeft","potentialTop","calcPosition","hideDragArea","requestAnimationFrame","_this$dragPositionBou2","dragSize","dragBoxSize","border","backgroundColor","width","height","left","top","display","_this$dragPositionBou3","_this$getContainerRec","getContainerRect","newTop","newLeft","realTop","realLeft","realBottom","realRight","state","bottom","right","setState","_props$placement","placement","_props$offsetY","offsetY","_props$offsetX","offsetX","_placement$split","split","placementY","placementX","_proto","prototype","getContainer","useCache","dom","_this$props$positionM","positionMode","findParent","parent","excludeOwn","documentElement","findAbsolutePositionParent","innerWidth","innerHeight","scrollLeft","scrollTop","scrollerScrollLeft","scrollerScrollTop","borderLeftWidth","borderTopWidth","containerRect","getBoundingClientRect","containerStyle","parseFloat","borderRightWidth","borderBottomWidth","offsetWidth","clientWidth","offsetHeight","clientHeight","_getScaleRatio","scaleX","rect","magnification","round","getScaleRatio","_this$draggerRef$getB","componentDidMount","_this2","componentWillUnmount","_this$__resizeDispose","_this$__bodyClassDisp","_this$__moveDisposer","_this$__clickDisposer","_this$__upDisposer","render","_this3","_this$props","className","zIndex","children","_this$props$positionM2","stl","_extends","React","createElement","Fragment","ref","r","pointerEvents","boxSizing","borderRadius","cx","onMouseDown","onMouseUp","key","get","_this$props2","boundsX","boundsY","_this$props2$placemen","_this$getContainerRec2","containerWidth","containerHeight","_placement$split2","defaultBounds","minBound","maxBound","_this$curPositionKey","curPositionKey","y","x","positionStyles","Component","defaultProps"],"mappings":"2yBAOgB,SAAAA,EAA4BC,EAAsBC,GAC9D,IAAMC,EAAQC,OAAOC,iBAAiBJ,GAChCK,EAAWH,EAAMI,iBAAiB,YAClCC,EAAYL,EAAMI,iBAAiB,aACnCE,EAASN,EAAMI,iBAAiB,UAChCG,EAAcP,EAAMI,iBAAiB,eACrCI,EAAUR,EAAMI,iBAAiB,WACjCK,EAAaT,EAAMI,iBAAiB,eAE1C,OAAQL,GAAgC,WAAbI,GACT,SAAdE,GACW,SAAXC,GACgB,SAAhBC,GACAC,EAAQE,SAAS,UACjBF,EAAQE,SAAS,WACjBF,EAAQE,SAAS,WACjBD,EAAWC,SAAS,cACpBD,EAAWC,SAAS,gBACpBD,EAAWC,SAAS,SAC5B,CA2DgB,SAAAC,EAAMC,EAAeC,EAAaC,GAC9C,OAAOC,KAAKF,IAAIE,KAAKD,IAAIF,EAAOC,GAAMC,EAC1C,CCtFa,IAAAE,EAAiB,CAAC,WAAY,YAAa,cAAe,gBCW1DC,EAAIC,EAACC,gBAAC,yBACNC,eAAa,SAAAC,GAYtB,SAAAD,EAAYE,OAAwBC,GAChCA,EAAAF,EAAAG,KAAAC,KAAMH,IAAMG,MAcRC,uBAAeH,EACfI,cAAoC,KAAIJ,EACxCK,UAAgC,KAAIL,EAsK5CM,WAAoC,KAAIN,EAExCO,YAAa,EAAKP,EAElBQ,WAAKR,EAAAA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AM6B,WAA3BjL,EACFkL,aAA2C,CAC9CnC,OAAQ,KACRtD,QAAS,GACTF,QAAS,GACTF,UAAW,eACXxC,UAAU,EACVC,SAAU,OACVV,cAAc,EACdgE,aAAc"}
|
package/dist/index.modern.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"react";import{prefixClassname as
|
|
1
|
+
import t from"react";import{prefixClassname as i,classNames as e}from"@ohkit/prefix-classname";import{findParent as s,addEventListener as o,addClass as r}from"@ohkit/dom-helper";function a(){return a=Object.assign?Object.assign.bind():function(t){for(var i=1;i<arguments.length;i++){var e=arguments[i];for(var s in e)({}).hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},a.apply(null,arguments)}function h(t,i){const e=window.getComputedStyle(t),s=e.getPropertyValue("position"),o=e.getPropertyValue("transform"),r=e.getPropertyValue("filter"),a=e.getPropertyValue("perspective"),h=e.getPropertyValue("contain"),n=e.getPropertyValue("will-change");return i&&"static"!==s||"none"!==o||"none"!==r||"none"!==a||h.includes("paint")||h.includes("layout")||h.includes("strict")||n.includes("transform")||n.includes("perspective")||n.includes("filter")}function n(t,i,e){return Math.min(Math.max(t,i),e)}const d=["top-left","top-right","bottom-left","bottom-right"],l=i("ohkit-draggable-box__");class p extends t.Component{constructor(t){super(t),this.prePositionMode=void 0,this.preDraggerRef=null,this.container=null,this.draggerRef=null,this.isDragging=!1,this.axisX=void 0,this.axisY=void 0,this.dX=0,this.dY=0,this.startTop=0,this.startLeft=0,this.cachedScaleX=1,this.cachedScaleY=1,this.__moveDisposer=void 0,this.__clickDisposer=void 0,this.__bodyClassDisposer=void 0,this.__upDisposer=void 0,this.__resizeDisposer=void 0,this.dragAreaRef=null,this.enableDrag=()=>{var t,i;this.reportStartPosition(),null==(t=this.__moveDisposer)||t.call(this),this.__moveDisposer=o(document,"mousemove",t=>{this.__clickDisposer||Math.sqrt(Math.pow(this.dX,2)+Math.pow(this.dY,2))>5&&(this.__clickDisposer=o(document,"click",t=>{t.stopPropagation()},!0),this.__bodyClassDisposer=r([document.body,this.draggerRef],l("moving"))||void 0,this.props.showDragArea&&this.dragAreaRef&&this.showDragArea()),this.dragging(t)},!0),null==(i=this.__upDisposer)||i.call(this),this.__upDisposer=o(document,"mouseup",t=>{this.endDrag(),t.stopPropagation(),t.preventDefault()},!0)},this.startDrag=t=>{2!==t.nativeEvent.button&&(this.axisX=t.nativeEvent.pageX,this.axisY=t.nativeEvent.pageY,this.props.disabled||this.enableDrag())},this.dragging=t=>{this.isDragging=!0;const{lockAxis:i}=this.props,{minX:e,maxX:s,minY:o,maxY:r}=this.dragPositionBoundaries,a=this.cachedScaleY;this.dX=(t.pageX-(this.axisX||0))/this.cachedScaleX,this.dY=(t.pageY-(this.axisY||0))/a;let h=this.dX,n=this.dY;"x"===i?n=0:"y"===i&&(h=0);const d=this.startLeft+h,l=this.startTop+n;"y"!==i&&(d<e?h=e-this.startLeft:d>s&&(h=s-this.startLeft)),"x"!==i&&(l<o?n=o-this.startTop:l>r&&(n=r-this.startTop)),this.draggerRef&&(this.draggerRef.style.transform=`translate(${h}px, ${n}px)`),t.stopPropagation()},this.endDrag=()=>{var t,i,e;this.isDragging&&(this.calcPosition(),this.draggerRef&&(this.draggerRef.style.transform=""),this.props.showDragArea&&this.hideDragArea()),null==(t=this.__moveDisposer)||t.call(this),this.__moveDisposer=void 0,this.__clickDisposer&&requestAnimationFrame(()=>{this.__clickDisposer&&(this.__clickDisposer(),this.__clickDisposer=void 0)}),null==(i=this.__upDisposer)||i.call(this),this.__upDisposer=void 0,null==(e=this.__bodyClassDisposer)||e.call(this),this.__bodyClassDisposer=void 0,this.isDragging=!1},this.showDragArea=()=>{if(!this.props.showDragArea||!this.dragAreaRef)return;const{lockAxis:t}=this.props,{minX:i,maxX:e,minY:s,maxY:o}=this.dragPositionBoundaries,r=this.dragBoxSize;this.dragAreaRef.style.border="1px dashed var(--ohkit-color-primary, #1890ff)",this.dragAreaRef.style.backgroundColor="rgba(173, 216, 230, 0.2)","x"===t?(this.dragAreaRef.style.width=`${e-i+r.width}px`,this.dragAreaRef.style.height="2px",this.dragAreaRef.style.left=`${i}px`,this.dragAreaRef.style.top=`${this.startTop+r.height/2}px`):"y"===t?(this.dragAreaRef.style.width="2px",this.dragAreaRef.style.height=`${o-s+r.height}px`,this.dragAreaRef.style.left=`${this.startLeft+r.width/2}px`,this.dragAreaRef.style.top=`${s}px`):(this.dragAreaRef.style.width=`${e-i+r.width}px`,this.dragAreaRef.style.height=`${o-s+r.height}px`,this.dragAreaRef.style.left=`${i}px`,this.dragAreaRef.style.top=`${s}px`),this.dragAreaRef.style.display="block"},this.hideDragArea=()=>{this.dragAreaRef&&(this.dragAreaRef.style.display="none")},this.calcPosition=()=>{const{lockAxis:t}=this.props,{minX:i,maxX:e,minY:s,maxY:o}=this.dragPositionBoundaries,{height:r,width:a}=this.getContainerRect();let h=this.startTop,d=this.startLeft;"y"!==t&&(d+=this.dX),"x"!==t&&(h+=this.dY);const l=n(h,s,o),p=n(d,i,e),g=r-l-this.dragBoxSize.height,c=a-p-this.dragBoxSize.width;l===this.state.top&&p===this.state.left&&this.state.bottom===g&&this.state.right===c||this.setState({top:l,left:p,bottom:g,right:c}),this.startTop=l,this.startLeft=p,this.dX=this.dY=0};const{placement:i="bottom-right",offsetY:e=20,offsetX:s=20}=t,[a,h]=i.split("-");this.state={top:"top"===a?e:void 0,bottom:"bottom"===a?e:void 0,left:"left"===h?s:void 0,right:"right"===h?s:void 0}}getContainer(t=!0){const{positionMode:i="fixed"}=this.props;var e;return this.container&&t&&this.prePositionMode===i&&this.preDraggerRef===this.draggerRef||(this.prePositionMode=i,this.preDraggerRef=this.draggerRef,this.container="fixed"===i?(e=this.draggerRef)?s(e,t=>h(t,!1),{excludeOwn:!0}):document.documentElement:function(t){return t?s(t,t=>h(t,!0),{excludeOwn:!0}):document.body}(this.draggerRef)),this.container}getContainerRect(){const t=this.getContainer(!1);if(!t)return{width:window.innerWidth,height:window.innerHeight,left:0,top:0,scrollLeft:0,scrollTop:0,scrollerScrollLeft:0,scrollerScrollTop:0,borderLeftWidth:0,borderTopWidth:0};const i=t.getBoundingClientRect(),e=window.getComputedStyle(t),s=parseFloat(e.borderLeftWidth)||0,o=parseFloat(e.borderTopWidth)||0,r=parseFloat(e.borderRightWidth)||0,a=parseFloat(e.borderBottomWidth)||0;return{width:i.width/this.cachedScaleX-s-r-(t.offsetWidth-t.clientWidth-s-r),height:i.height/this.cachedScaleY-o-a-(t.offsetHeight-t.clientHeight-o-a),left:i.left/this.cachedScaleX,top:i.top/this.cachedScaleY,scrollLeft:t.scrollLeft,scrollTop:t.scrollTop,borderLeftWidth:s,borderTopWidth:o}}get dragBoxSize(){let t=0,i=0;return this.draggerRef&&(t=this.draggerRef.offsetWidth,i=this.draggerRef.offsetHeight),{height:i,width:t}}get dragPositionBoundaries(){const{boundsX:t,boundsY:i,placement:e="bottom-right"}=this.props,s=this.dragBoxSize,{width:o,height:r}=this.getContainerRect(),[a,h]=e.split("-"),d={minX:0,maxX:Math.max(o-s.width,0),minY:0,maxY:Math.max(r-s.height,0)};let{minX:l,maxX:p,minY:g,maxY:c}=d;if(t){const[i,e]=t;"left"===h?(void 0!==i&&(l=Math.max(l,i)),void 0!==e&&(p=Math.min(p,e))):void 0!==i&&void 0!==e?(l=Math.max(l,o-e-s.width),p=Math.min(p,o-i-s.width)):void 0!==i?p=Math.min(p,o-i-s.width):void 0!==e&&(l=Math.max(l,o-e-s.width))}if(i){const[t,e]=i;"top"===a?(void 0!==t&&(g=Math.max(g,t)),void 0!==e&&(c=Math.min(c,e))):void 0!==t&&void 0!==e?(g=Math.max(g,r-e-s.height),c=Math.min(c,r-t-s.height)):void 0!==t?c=Math.min(c,r-t-s.height):void 0!==e&&(g=Math.max(g,r-e-s.height))}return l=n(l,d.minX,d.maxX),p=n(p,l,d.maxX),g=n(g,d.minY,d.maxY),c=n(c,g,d.maxY),{minX:l,maxX:p,minY:g,maxY:c}}get curPositionKey(){let{placement:t}=this.props;return t&&d.includes(t)||(t="bottom-right"),t.split("-")}get position(){const[t,i]=this.curPositionKey,e={};return void 0!==this.state[t]&&(e[t]=`${this.state[t]}px`),void 0!==this.state[i]&&(e[i]=`${this.state[i]}px`),e}reportStartPosition(){if(this.draggerRef){const{scaleX:t,scaleY:i}=function(t){if(!t)return{scaleX:1,scaleY:1};const i=t.getBoundingClientRect();let e=1,s=1;const o=1e4;return e=t.offsetWidth>0?Math.round(i.width/t.offsetWidth*o)/o:1,s=t.offsetHeight>0?Math.round(i.height/t.offsetHeight*o)/o:1,{scaleX:e,scaleY:s}}(this.getContainer());this.cachedScaleX=t,this.cachedScaleY=i;const{top:e,left:s}=this.draggerRef.getBoundingClientRect(),o=this.getContainerRect();this.startTop=e/i-o.top+o.scrollTop-o.borderTopWidth,this.startLeft=s/i-o.left+o.scrollLeft-o.borderLeftWidth}}componentDidMount(){this.reportStartPosition(),this.calcPosition(),this.__resizeDisposer=o(window,"resize",()=>{this.calcPosition()})}componentWillUnmount(){var t,i,e,s,o;null==(t=this.__resizeDisposer)||t.call(this),null==(i=this.__bodyClassDisposer)||i.call(this),null==(e=this.__moveDisposer)||e.call(this),null==(s=this.__clickDisposer)||s.call(this),null==(o=this.__upDisposer)||o.call(this)}render(){const{className:i,zIndex:s,children:o,showDragArea:r,positionMode:h="fixed"}=this.props,{startDrag:n,endDrag:d}=this,p=a({zIndex:s},this.position,{position:h});/*#__PURE__*/return t.createElement(Fragment,null,r&&/*#__PURE__*/t.createElement("div",{className:l("drag-area"),ref:t=>{this.dragAreaRef=t},style:{display:"none",position:h,backgroundColor:"rgba(173, 216, 230, 0.2)",border:"1px dashed var(--ohkit-color-primary, #1890ff)",pointerEvents:"none",zIndex:(s||9999)-1,boxSizing:"border-box",borderRadius:"none"!==this.props.lockAxis?"2px":"0"}}),/*#__PURE__*/t.createElement("div",{className:e(l("container"),i),style:p,ref:t=>{this.draggerRef=t},onMouseDown:n,onMouseUp:d},o))}}p.defaultProps={zIndex:9999,offsetX:20,offsetY:20,placement:"bottom-right",disabled:!1,lockAxis:"none",showDragArea:!1,positionMode:"fixed"};export{p as DraggableBox,l as c,p as default};
|
|
2
2
|
//# sourceMappingURL=index.modern.mjs.map
|