UNPKG

@progress/kendo-react-data-tools

Version:

Includes React Pager & React Filter component, an intuitive interface to create complex filter descriptions. KendoReact Data Tools package

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