@progress/kendo-vue-treeview
Version:
75 lines (74 loc) • 3.11 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
*-------------------------------------------------------------------------------------------
*/
var n = Object.defineProperty;
var h = (s, e, t) => e in s ? n(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
var i = (s, e, t) => h(s, typeof e != "symbol" ? e + "" : e, t);
import { DOM_KENDO_ITEM_ID_FIELD as d, DOM_KENDO_TREEVIEW_GUID_FIELD as o } from "./utils/consts.mjs";
const r = 6;
class u {
/**
* @param event - The event that will be analyzed.
*/
constructor(e) {
i(this, "itemId");
i(this, "treeViewGuid");
i(this, "initialized", !1);
i(this, "destDomNodeWithMeta");
i(this, "destItemId");
i(this, "destTreeViewGuid");
this.event = e, this.itemId = e.itemHierarchicalIndex, this.treeViewGuid = e.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`—Indicates that the dragged item is positioned at the beginning of the destination item.
* * `after`—Indicates that the dragged item is positioned at the end of the destination item.
* * `child`—Indicates that the dragged item is positioned in the middle of the destination item.
* * `undefined`—Indicates that dropping is not allowed.
*/
getDropOperation() {
if (this.initialized && this.isDropAllowed) {
const { top: e, height: t } = this.destDomNodeWithMeta.getBoundingClientRect();
return e + t - this.event.clientY < r ? "after" : this.event.clientY - e < r ? "before" : "child";
} else
return;
}
setDestimationMeta(e) {
let t = e;
for (; t && !t[d]; )
t = t.parentNode;
t && t[d] && (this.destDomNodeWithMeta = t, this.destItemId = t[d], this.destTreeViewGuid = t[o]);
}
}
export {
u as TreeViewDragAnalyzer
};