Add coexistence checks to all enqueue methods to prevent loading both React and Grid.js assets simultaneously. Changes: - ReactAdmin.php: Only enqueue React assets when ?react=1 - Init.php: Skip Grid.js when React active on admin pages - Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0 - Customer.php, Product.php, License.php: Add coexistence checks Now the toggle between Classic and React versions works correctly. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
"use strict";
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = isEntirelySelected;
|
|
var _assertIsDefined = require("../utils/assert-is-defined");
|
|
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area"));
|
|
/**
|
|
* Internal dependencies
|
|
*/
|
|
|
|
/**
|
|
* Check whether the contents of the element have been entirely selected.
|
|
* Returns true if there is no possibility of selection.
|
|
*
|
|
* @param {HTMLElement} element The element to check.
|
|
*
|
|
* @return {boolean} True if entirely selected, false if not.
|
|
*/
|
|
function isEntirelySelected(element) {
|
|
if ((0, _isInputOrTextArea.default)(element)) {
|
|
return element.selectionStart === 0 && element.value.length === element.selectionEnd;
|
|
}
|
|
if (!element.isContentEditable) {
|
|
return true;
|
|
}
|
|
const {
|
|
ownerDocument
|
|
} = element;
|
|
const {
|
|
defaultView
|
|
} = ownerDocument;
|
|
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
|
|
const selection = defaultView.getSelection();
|
|
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
|
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
|
if (!range) {
|
|
return true;
|
|
}
|
|
const {
|
|
startContainer,
|
|
endContainer,
|
|
startOffset,
|
|
endOffset
|
|
} = range;
|
|
if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
|
|
return true;
|
|
}
|
|
const lastChild = element.lastChild;
|
|
(0, _assertIsDefined.assertIsDefined)(lastChild, 'lastChild');
|
|
const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? /** @type {Text} */endContainer.data.length : endContainer.childNodes.length;
|
|
return isDeepChild(startContainer, element, 'firstChild') && isDeepChild(endContainer, element, 'lastChild') && startOffset === 0 && endOffset === endContainerContentLength;
|
|
}
|
|
|
|
/**
|
|
* Check whether the contents of the element have been entirely selected.
|
|
* Returns true if there is no possibility of selection.
|
|
*
|
|
* @param {HTMLElement|Node} query The element to check.
|
|
* @param {HTMLElement} container The container that we suspect "query" may be a first or last child of.
|
|
* @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild"
|
|
*
|
|
* @return {boolean} True if query is a deep first/last child of container, false otherwise.
|
|
*/
|
|
function isDeepChild(query, container, propName) {
|
|
/** @type {HTMLElement | ChildNode | null} */
|
|
let candidate = container;
|
|
do {
|
|
if (query === candidate) {
|
|
return true;
|
|
}
|
|
candidate = candidate[propName];
|
|
} while (candidate);
|
|
return false;
|
|
}
|
|
//# sourceMappingURL=is-entirely-selected.js.map
|