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

131 lines (130 loc) 4.87 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 o, getColumnIndex as x, getRowIndex as I } from "./utils.mjs"; const oe = (u) => { var T; const { onRelease: D, childRef: K } = u, { enabled: q, drag: p, mode: c, 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 }), [M, f] = t.useState(null), P = t.useRef(void 0), g = t.useRef(!1), E = t.useRef(!1), j = t.useCallback((s) => { const { event: e } = s; if (E.current = ee(e.originalEvent.target), E.current || !r.current) return; P.current = te(r.current.element); const n = r.current.element && r.current.element.ownerDocument; if (!n) return; e.originalEvent.stopImmediatePropagation(); 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 (!E.current && !(!p || c === "single") && ((Math.abs(l - e.clientY) > 5 || Math.abs(n - e.clientX) > 5) && (g.current = !0), e.originalEvent.stopImmediatePropagation(), g.current)) { const v = ne(P.current); f({ top: Math.min(l, e.clientY) - v.top, left: Math.min(n, e.clientX) - v.left, width: Math.abs(e.clientX - n), height: Math.abs(e.clientY - l) }); } }, [f, p, c] ), A = t.useCallback( (s) => { const { event: e } = s, { clientX: n, clientY: l, scrollX: v, scrollY: G, pressedElement: J } = d.current; if (E.current || !r.current) return; const y = r.current.element && r.current.element.ownerDocument; if (y) { if (e.originalEvent.stopImmediatePropagation(), g.current) { const i = e.scrollY - G, R = e.scrollX - v, 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 = y.elementFromPoint(a, h), C = i > 0 || R > 0 ? J : Q, w = y.elementFromPoint(L, m); if (b.style.visibility = "", !C || !w) return; const S = o(C, "TD"), U = o(S, "TR"), k = o(w, "TD"), V = o(k, "TR"), F = x(S), O = I(U), H = x(k), N = I(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: c, cell: X, isDrag: !0 }); } else { const i = y.elementFromPoint(n, l); if (!i) return; const R = o(i, "TD"), h = o(i, "TR"), a = x(R), m = I(h); R && 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: c, cell: X, isDrag: !1 }); } f(null), g.current = !1, d.current = { clientX: 0, clientY: 0, scrollX: 0, scrollY: 0, pressedElement: null }; } }, [f, c, 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: K }, u.children ), M && W.createPortal( /* @__PURE__ */ t.createElement( "div", { ref: Y, style: { ...M, position: "fixed" }, className: "k-marquee k-marquee-color" } ), (T = B()) == null ? void 0 : T.body )) : t.cloneElement(t.Children.only(u.children), { ref: K }); }; export { oe as TableSelection };