@jupyterlab/apputils
Version:
JupyterLab - Application Utilities
56 lines • 2.01 kB
JavaScript
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { ArrayExt } from '@lumino/algorithm';
import { UUID } from '@lumino/coreutils';
import { ElementExt } from '@lumino/domutils';
/**
* The namespace for DOM utilities.
*/
export var DOMUtils;
(function (DOMUtils) {
/**
* Get the index of the node at a client position, or `-1`.
*/
function hitTestNodes(nodes, x, y) {
return ArrayExt.findFirstIndex(nodes, node => {
return ElementExt.hitTest(node, x, y);
});
}
DOMUtils.hitTestNodes = hitTestNodes;
/**
* Find the first element matching a class name.
* Only use this function when the element existence is guaranteed.
*/
function findElement(parent, className) {
return parent.querySelector(`.${className}`);
}
DOMUtils.findElement = findElement;
/**
* Find the first element matching a class name.
*/
function findElements(parent, className) {
return parent.getElementsByClassName(className);
}
DOMUtils.findElements = findElements;
/**
* Create a DOM id with prefix "id-" to solve bug for UUIDs beginning with numbers.
*/
function createDomID() {
return `id-${UUID.uuid4()}`;
}
DOMUtils.createDomID = createDomID;
/**
* Check whether the active element descendant from given parent is editable.
* When checking active elements it includes elements in the open shadow DOM.
*/
function hasActiveEditableElement(parent, root = document) {
const element = root.activeElement;
return !!(element &&
parent.contains(element) &&
(element.matches(':read-write') ||
(element.shadowRoot &&
hasActiveEditableElement(element.shadowRoot, element.shadowRoot))));
}
DOMUtils.hasActiveEditableElement = hasActiveEditableElement;
})(DOMUtils || (DOMUtils = {}));
//# sourceMappingURL=domutils.js.map