UNPKG

@progress/kendo-react-treeview

Version:

React TreeView displays hierarchical data in a traditional tree structure, supports user interaction. KendoReact TreeView package

65 lines (64 loc) 2.77 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { DOM_KENDO_ITEM_ID_FIELD as i, DOM_KENDO_TREEVIEW_GUID_FIELD as r } from "./utils/consts.mjs"; const s = 6; class h { /** * @param event - The event that will be analyzed. */ constructor(t) { this.event = t, this.initialized = !1, this.destItemId = "", this.destTreeViewGuid = "", this.itemId = t.itemHierarchicalIndex, this.treeViewGuid = t.target.guid; } /** * The method which initializes the analyzer. * Invoke the method before you call any other methods. * * @returns - The analyzer object of the `drag` event. */ init() { return this.initialized || (this.setDestimationMeta(document.elementFromPoint(this.event.clientX, this.event.clientY)), this.initialized = !0), this; } /** * Returns `true` if dropping is allowed. Otherwise, returns `false`. */ get isDropAllowed() { return this.initialized && this.destItemId && this.destTreeViewGuid ? !`${this.destTreeViewGuid}_${this.destItemId}_`.startsWith(`${this.treeViewGuid}_${this.itemId}_`) : !1; } /** * Returns an object which contains: * * The `itemHierarchicalIndex` of the destination item (the item below the dragged item) and * * The `guid` of the destination TreeView (the TreeView which renders the destination item). */ get destinationMeta() { return { itemHierarchicalIndex: this.destItemId, treeViewGuid: this.destTreeViewGuid }; } /** * Returns the specific drop operation. * * @returns - The following values are returned: * * `before`&mdash;Indicates that the dragged item is positioned at the beginning of the destination item. * * `after`&mdash;Indicates that the dragged item is positioned at the end of the destination item. * * `child`&mdash;Indicates that the dragged item is positioned in the middle of the destination item. * * `undefined`&mdash;Indicates that dropping is not allowed. */ getDropOperation() { if (this.initialized && this.isDropAllowed) { const { top: t, height: e } = this.destDomNodeWithMeta.getBoundingClientRect(); return t + e - this.event.clientY < s ? "after" : this.event.clientY - t < s ? "before" : "child"; } } setDestimationMeta(t) { let e = t; for (; e && !e[i]; ) e = e.parentNode; e && e[i] && (this.destDomNodeWithMeta = e, this.destItemId = e[i], this.destTreeViewGuid = e[r]); } } export { h as TreeViewDragAnalyzer };