@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.75 kB
JavaScript
/**
* @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(l){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const r in l)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(l,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>l[r]})}}return e.default=l,Object.freeze(e)}const c=p(g);class d{constructor(e,r,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 s=this.getColumnIndex(t,n);if(this.startGroup=this.getGroupIndex(t),s>=0){const u=this.columns[s];(u.reorderable&&this.reorderable||u.groupable&&this.groupable)&&(this.startColumn=s)}},this.dragHandler=(t,n)=>{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 s=!this.isValid();s&&(this.currentColumn=-1,this.currentGroup=-1);const u=this.currentColumn>=0?n.children[this.columns[this.currentColumn].index]:this.isTargetGroupingContainer(t)?t.originalEvent.target:this.groupPanelDivElement&&this.groupPanelDivElement.children[this.currentGroup];this.updateDragElementClue(t,n,u,s),this.updateDropElementClue(t,n,u,s)},this.releaseHandler=t=>{const n=this.startColumn,s=this.currentColumn,u=this.startGroup,o=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&&s>=0?this.columnReorder(n,s,t.originalEvent):u>=0&&o>=0?this.groupReorder(u,o,t.originalEvent):n>=0&&o>=0&&this.columnToGroup(n,o,t.originalEvent))},this.columnReorder=e,this.groupReorder=r,this.columnToGroup=i}get dragClueRef(){return this.refDragElementClue}get dropClueRef(){return this.refDropElementClue}get getCurrentGroupsLength(){const e=this.groupPanelDivElement&&this.groupPanelDivElement.children;return e&&e.length||0}get dragElementClue(){return this.refDragElementClue.current}get dropElementClue(){return this.refDropElementClue.current}getColumnIndex(e,r){if(!r||r.parentElement===this.groupPanelDivElement)return-1;const i=h.getIndex(e,r);if(i===-1)return-1;for(let t=0;t<r.parentNode.children.length;t++)if(r.parentNode.children[t]===r)return this.columns.findIndex(n=>n.index===i&&n.depth===t);return-1}isTargetGroupingContainer(e){const r=e.originalEvent.target;return r.className.indexOf?r.className.indexOf("k-grouping-drop-container")!==-1:!1}getGroupIndex(e){return h.getIndex(e,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(e,r,i,t){if(!this.dragElementClue)return;const n=this.startColumn>=0?r.children[this.columns[this.startColumn].index].innerText:r.innerText;this.dragElementClue.setState({visible:!0,top:e.pageY+10,left:e.pageX,innerText:n,status:t||!i?"k-i-cancel":"k-i-plus"})}updateDropElementClue(e,r,i,t){if(!this.dropElementClue)return;if(t||!i){this.dropElementClue.setState({visible:!1});return}const n=i.getBoundingClientRect(),u=(i.closest(".k-grouping-header")||i).getBoundingClientRect();let o=n.left+e.pageX-e.clientX-6;!this.isTargetGroupingContainer(e)&&(this.currentColumn>this.startColumn||this.currentGroup>this.startGroup&&this.startGroup!==-1)&&this.dir!=="rtl"&&(o+=n.width);const a=u.top+e.pageY-e.clientY;this.dropElementClue.setState({visible:!0,top:a,left:o,height:this.currentColumn>=0?r.clientHeight:u.height})}}exports.CommonDragLogic=d;