@progress/kendo-react-data-tools
Version:
Includes React Pager & React Filter component, an intuitive interface to create complex filter descriptions. KendoReact Data Tools package
133 lines (132 loc) • 4.91 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 client";
import * as t from "react";
import * as Z from "react-dom";
import { useDocument as _, Draggable as $ } from "@progress/kendo-react-common";
import { getSelectionOptions as ee, isInNonSelectable as te, relativeContextElement as ne, getOffset as le, closestTagName as c, getColumnIndex as x, getRowIndex as I } from "./utils.mjs";
const ce = (d) => {
var T;
const { onRelease: D, childRef: K } = d, {
enabled: j,
drag: p,
mode: s,
cell: X
} = ee(d.selectable), o = t.useRef(null), Y = t.useRef(null), f = t.useRef({ clientX: 0, clientY: 0, scrollX: 0, scrollY: 0, pressedElement: null }), [M, g] = t.useState(null), P = t.useRef(void 0), E = t.useRef(!1), v = t.useRef(!1), z = t.useCallback((i) => {
var r;
const { event: e } = i;
if (v.current = te(e.originalEvent.target), v.current || !o.current)
return;
P.current = ne(o.current.element);
const n = (r = o.current.element) == null ? void 0 : r.ownerDocument;
if (!n)
return;
e.originalEvent.stopImmediatePropagation();
const l = n.elementFromPoint(e.clientX, e.clientY);
f.current = {
clientY: e.clientY,
clientX: e.clientX,
scrollX: e.scrollX,
scrollY: e.scrollY,
pressedElement: l
};
}, []), A = t.useCallback(
(i) => {
const { event: e } = i, { clientX: n, clientY: l } = f.current;
if (!v.current && !(!p || s === "single") && ((Math.abs(l - e.clientY) > 5 || Math.abs(n - e.clientX) > 5) && (E.current = !0), e.originalEvent.stopImmediatePropagation(), E.current)) {
const r = le(P.current);
g({
top: Math.min(l, e.clientY) - r.top,
left: Math.min(n, e.clientX) - r.left,
width: Math.abs(e.clientX - n),
height: Math.abs(e.clientY - l)
});
}
},
[g, p, s]
), B = t.useCallback(
(i) => {
var C;
const { event: e } = i, { clientX: n, clientY: l, scrollX: r, scrollY: J, pressedElement: L } = f.current;
if (v.current || !o.current)
return;
const y = (C = o.current.element) == null ? void 0 : C.ownerDocument;
if (y) {
if (e.originalEvent.stopImmediatePropagation(), E.current) {
const a = e.scrollY - J, R = e.scrollX - r, h = Math.min(l, e.clientY), m = Math.min(n, e.clientX), u = Math.max(l, e.clientY), Q = Math.max(n, e.clientX), b = Y.current;
if (!b)
return;
b.style.visibility = "hidden";
const U = y.elementFromPoint(m, h), w = a > 0 || R > 0 ? L : U, S = y.elementFromPoint(Q, u);
if (b.style.visibility = "", !w || !S)
return;
const k = c(w, "TD"), V = c(k, "TR"), F = c(S, "TD"), W = c(F, "TR"), O = x(k), H = I(V), N = x(F), q = I(W);
O !== void 0 && H !== void 0 && N !== void 0 && q !== void 0 && D({
nativeEvent: e.originalEvent,
startRowIndex: H,
startColIndex: O,
endRowIndex: q,
endColIndex: N,
altKey: e.altKey,
shiftKey: e.shiftKey,
ctrlKey: e.ctrlKey,
metaKey: e.metaKey,
mode: s,
cell: X,
isDrag: !0
});
} else {
const a = y.elementFromPoint(n, l);
if (!a)
return;
const R = c(a, "TD"), h = c(a, "TR"), m = x(R), u = I(h);
R && h && u !== void 0 && m !== void 0 && D({
nativeEvent: e.originalEvent,
startRowIndex: u,
startColIndex: m,
endRowIndex: u,
endColIndex: m,
altKey: e.altKey,
shiftKey: e.shiftKey,
ctrlKey: e.ctrlKey,
metaKey: e.metaKey,
mode: s,
cell: X,
isDrag: !1
});
}
g(null), E.current = !1, f.current = { clientX: 0, clientY: 0, scrollX: 0, scrollY: 0, pressedElement: null };
}
},
[g, s, X, D]
), G = _(Y);
return j ? /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement(
$,
{
onPress: z,
onDrag: A,
onRelease: B,
ref: o,
childRef: K
},
d.children
), M && Z.createPortal(
/* @__PURE__ */ t.createElement(
"div",
{
ref: Y,
style: { ...M, position: "fixed" },
className: "k-marquee k-marquee-color"
}
),
(T = G()) == null ? void 0 : T.body
)) : t.cloneElement(t.Children.only(d.children), { ref: K });
};
export {
ce as TableSelection
};