@sanity/form-builder
Version:
Sanity form builder
24 lines (21 loc) • 941 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hasFocusAtPath = hasFocusAtPath;
exports.hasFocusWithinPath = hasFocusWithinPath;
var _types = require("@sanity/types");
// Tests whether a keyed value matches a given keyed pathSegment
function matchesSegment(segment, value) {
return (0, _types.isKeyedObject)(value) && (0, _types.isKeySegment)(segment) && value._key === segment._key;
}
// Utility to check if the given focusPath terminates at the given keyed value
// E.g. focus is on the value itself and not a child node
function hasFocusAtPath(path, value) {
return path.length === 1 && matchesSegment(path[0], value);
}
// Utility to check if the given focusPath terminates at a child node of the given keyed value
// E.g. focus is on a child node of the value and not the value itself
function hasFocusWithinPath(path, value) {
return path.length > 1 && matchesSegment(path[0], value);
}