UNPKG

@progress/kendo-react-grid

Version:

React Data Grid (Table) provides 100+ ready-to-use data grid features. KendoReact Grid package

9 lines (8 loc) 4.98 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react"),h=require("@progress/kendo-react-data-tools");function p(o){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(r,e,i.get?i:{enumerable:!0,get:()=>o[e]})}}return r.default=o,Object.freeze(r)}const c=p(g);class d{constructor(r,e,i){this.refDragElementClue=c.createRef(),this.refDropElementClue=c.createRef(),this.columns=[],this.reorderable=!1,this.groupable=!1,this.startColumn=-1,this.startGroup=-1,this.currentColumn=-1,this.currentGroup=-1,this.groupPanelDivElement=null,this.refGroupPanelDiv=t=>{this.groupPanelDivElement=t&&t.children?t.children[0]:t},this.pressHandler=(t,n)=>{const u=this.getColumnIndex(t,n);if(this.startGroup=this.getGroupIndex(t),u>=0){const s=this.columns[u];(s.reorderable&&this.reorderable||s.groupable&&this.groupable)&&(this.startColumn=u)}},this.dragHandler=(t,n)=>{var l,a;if(t.isTouch||t.originalEvent.preventDefault(),t.originalEvent.stopPropagation(),this.startColumn===-1&&this.startGroup===-1)return;this.currentColumn=this.getColumnIndex(t,n),this.currentGroup=this.isTargetGroupingContainer(t)?this.getCurrentGroupsLength:this.getGroupIndex(t);const u=!this.isValid();u&&(this.currentColumn=-1,this.currentGroup=-1);let s=null;this.currentColumn>=0?s=n.children[this.columns[this.currentColumn].index]:this.isTargetGroupingContainer(t)?s=this.getEventTarget(t):s=(a=(l=this.groupPanelDivElement)==null?void 0:l.children[this.currentGroup])!=null?a:null,this.updateDragElementClue(t,n,s,u),this.updateDropElementClue(t,n,s,u)},this.releaseHandler=t=>{const n=this.startColumn,u=this.currentColumn,s=this.startGroup,l=this.currentGroup;t.originalEvent.preventDefault(),this.dropElementClue&&this.dropElementClue.setState({visible:!1}),this.dragElementClue&&this.dragElementClue.setState({visible:!1});const a=this.isValid();this.startColumn=this.startGroup=this.currentColumn=this.currentGroup=-1,a&&(n>=0&&u>=0?this.columnReorder(n,u,t.originalEvent):s>=0&&l>=0?this.groupReorder(s,l,t.originalEvent):n>=0&&l>=0&&this.columnToGroup(n,l,t.originalEvent))},this.columnReorder=r,this.groupReorder=e,this.columnToGroup=i}get dragClueRef(){return this.refDragElementClue}get dropClueRef(){return this.refDropElementClue}get getCurrentGroupsLength(){const r=this.groupPanelDivElement&&this.groupPanelDivElement.children;return r&&r.length||0}get dragElementClue(){return this.refDragElementClue.current}get dropElementClue(){return this.refDropElementClue.current}getColumnIndex(r,e){if(!e||e.parentElement===this.groupPanelDivElement)return-1;const i=h.getIndex(r,e);if(i===-1)return-1;for(let t=0;t<e.parentNode.children.length;t++)if(e.parentNode.children[t]===e)return this.columns.findIndex(n=>n.index===i&&n.depth===t);return-1}getEventTarget(r){var t,n;const e=r.originalEvent,i=(t=e.target)==null?void 0:t.ownerDocument;return(n=i==null?void 0:i.elementFromPoint(e.clientX,e.clientY))!=null?n:null}isTargetGroupingContainer(r){var i,t;const e=this.getEventTarget(r);return(t=(i=e==null?void 0:e.classList)==null?void 0:i.contains("k-grouping-drop-container"))!=null?t:!1}getGroupIndex(r){return h.getIndex(r,this.groupPanelDivElement)}isValid(){return this.startGroup>=0?this.currentGroup>=0&&this.currentGroup!==this.startGroup:this.startColumn===-1?!1:this.currentGroup>=0?this.columns[this.startColumn].groupable===!0&&this.groupable===!0:this.reorderable===!0&&this.currentColumn>=0&&this.currentColumn!==this.startColumn&&this.columns[this.startColumn].reorderable===!0&&this.columns[this.currentColumn].parentIndex===this.columns[this.startColumn].parentIndex}updateDragElementClue(r,e,i,t){if(!this.dragElementClue)return;const n=this.startColumn>=0?e.children[this.columns[this.startColumn].index].innerText:e.innerText;this.dragElementClue.setState({visible:!0,top:r.pageY+10,left:r.pageX,innerText:n,status:t||!i?"k-i-cancel":"k-i-plus"})}updateDropElementClue(r,e,i,t){if(!this.dropElementClue)return;if(t||!i){this.dropElementClue.setState({visible:!1});return}const n=i.getBoundingClientRect(),s=(i.closest(".k-grouping-header")||i).getBoundingClientRect();let l=n.left+r.pageX-r.clientX-6;!this.isTargetGroupingContainer(r)&&(this.currentColumn>this.startColumn||this.currentGroup>this.startGroup&&this.startGroup!==-1)&&this.dir!=="rtl"&&(l+=n.width);const a=s.top+r.pageY-r.clientY;this.dropElementClue.setState({visible:!0,top:a,left:l,height:this.currentColumn>=0?e.clientHeight:s.height})}}exports.CommonDragLogic=d;