app/assets/build/coco/book.js in coveragebook_components-0.8.2 vs app/assets/build/coco/book.js in coveragebook_components-0.8.3
- old
+ new
@@ -10441,11 +10441,11 @@
function src_default4(Alpine3) {
Alpine3.directive("intersect", (el, { value, expression, modifiers }, { evaluateLater: evaluateLater2, cleanup: cleanup2 }) => {
let evaluate2 = evaluateLater2(expression);
let options = {
rootMargin: getRootMargin(modifiers),
- threshold: getThreshhold(modifiers)
+ threshold: getThreshold(modifiers)
};
let observer2 = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting === (value === "leave"))
return;
@@ -10457,11 +10457,11 @@
cleanup2(() => {
observer2.disconnect();
});
});
}
- function getThreshhold(modifiers) {
+ function getThreshold(modifiers) {
if (modifiers.includes("full"))
return 0.99;
if (modifiers.includes("half"))
return 0.5;
if (!modifiers.includes("threshold"))
@@ -10505,12 +10505,13 @@
let result;
Alpine3.dontAutoEvaluateFunctions(() => {
evaluator((value2) => {
result = typeof value2 === "function" ? value2(input) : value2;
}, { scope: {
- $input: input,
- $money: formatMoney.bind({ el })
+ // These are "magics" we'll make available to the x-mask:function:
+ "$input": input,
+ "$money": formatMoney.bind({ el })
} });
});
return result;
};
processInputValue(el, false);
@@ -10554,19 +10555,25 @@
function restoreCursorPosition(el, template, callback) {
let cursorPosition = el.selectionStart;
let unformattedValue = el.value;
callback();
let beforeLeftOfCursorBeforeFormatting = unformattedValue.slice(0, cursorPosition);
- let newPosition = buildUp(template, stripDown(template, beforeLeftOfCursorBeforeFormatting)).length;
+ let newPosition = buildUp(
+ template,
+ stripDown(
+ template,
+ beforeLeftOfCursorBeforeFormatting
+ )
+ ).length;
el.setSelectionRange(newPosition, newPosition);
}
function stripDown(template, input) {
let inputToBeStripped = input;
let output = "";
let regexes = {
"9": /[0-9]/,
- a: /[a-zA-Z]/,
+ "a": /[a-zA-Z]/,
"*": /[a-zA-Z0-9]/
};
let wildcardTemplate = "";
for (let i2 = 0; i2 < template.length; i2++) {
if (["9", "a", "*"].includes(template[i2])) {
@@ -10612,11 +10619,13 @@
function formatMoney(input, delimiter = ".", thousands, precision = 2) {
if (input === "-")
return "-";
if (/^\D+$/.test(input))
return "9";
- thousands = thousands != null ? thousands : delimiter === "," ? "." : ",";
+ if (thousands === null || thousands === void 0) {
+ thousands = delimiter === "," ? "." : ",";
+ }
let addThousands = (input2, thousands2) => {
let output = "";
let counter = 0;
for (let i2 = input2.length - 1; i2 >= 0; i2--) {
if (input2[i2] === thousands2)
@@ -10647,36 +10656,76 @@
return template;
}
var module_default5 = src_default5;
// ../../../node_modules/@alpinejs/focus/dist/module.esm.js
- var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"];
+ var candidateSelectors = ["input", "select", "textarea", "a[href]", "button", "[tabindex]:not(slot)", "audio[controls]", "video[controls]", '[contenteditable]:not([contenteditable="false"])', "details>summary:first-of-type", "details"];
var candidateSelector = /* @__PURE__ */ candidateSelectors.join(",");
- var matches = typeof Element === "undefined" ? function() {
+ var NoElement = typeof Element === "undefined";
+ var matches = NoElement ? function() {
} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function(element) {
+ return element.getRootNode();
+ } : function(element) {
+ return element.ownerDocument;
+ };
var getCandidates = function getCandidates2(el, includeContainer, filter) {
var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
if (includeContainer && matches.call(el, candidateSelector)) {
candidates.unshift(el);
}
candidates = candidates.filter(filter);
return candidates;
};
- var isContentEditable = function isContentEditable2(node) {
- return node.contentEditable === "true";
+ var getCandidatesIteratively = function getCandidatesIteratively2(elements, includeContainer, options) {
+ var candidates = [];
+ var elementsToCheck = Array.from(elements);
+ while (elementsToCheck.length) {
+ var element = elementsToCheck.shift();
+ if (element.tagName === "SLOT") {
+ var assigned = element.assignedElements();
+ var content2 = assigned.length ? assigned : element.children;
+ var nestedCandidates = getCandidatesIteratively2(content2, true, options);
+ if (options.flatten) {
+ candidates.push.apply(candidates, nestedCandidates);
+ } else {
+ candidates.push({
+ scope: element,
+ candidates: nestedCandidates
+ });
+ }
+ } else {
+ var validCandidate = matches.call(element, candidateSelector);
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
+ candidates.push(element);
+ }
+ var shadowRoot = element.shadowRoot || // check for an undisclosed shadow
+ typeof options.getShadowRoot === "function" && options.getShadowRoot(element);
+ var validShadowRoot = !options.shadowRootFilter || options.shadowRootFilter(element);
+ if (shadowRoot && validShadowRoot) {
+ var _nestedCandidates = getCandidatesIteratively2(shadowRoot === true ? element.children : shadowRoot.children, true, options);
+ if (options.flatten) {
+ candidates.push.apply(candidates, _nestedCandidates);
+ } else {
+ candidates.push({
+ scope: element,
+ candidates: _nestedCandidates
+ });
+ }
+ } else {
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
+ }
+ }
+ }
+ return candidates;
};
- var getTabindex = function getTabindex2(node) {
- var tabindexAttr = parseInt(node.getAttribute("tabindex"), 10);
- if (!isNaN(tabindexAttr)) {
- return tabindexAttr;
+ var getTabindex = function getTabindex2(node, isScope) {
+ if (node.tabIndex < 0) {
+ if ((isScope || /^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || node.isContentEditable) && isNaN(parseInt(node.getAttribute("tabindex"), 10))) {
+ return 0;
+ }
}
- if (isContentEditable(node)) {
- return 0;
- }
- if ((node.nodeName === "AUDIO" || node.nodeName === "VIDEO" || node.nodeName === "DETAILS") && node.getAttribute("tabindex") === null) {
- return 0;
- }
return node.tabIndex;
};
var sortOrderedTabbables = function sortOrderedTabbables2(a2, b2) {
return a2.tabIndex === b2.tabIndex ? a2.documentOrder - b2.documentOrder : a2.tabIndex - b2.tabIndex;
};
@@ -10701,11 +10750,11 @@
};
var isTabbableRadio = function isTabbableRadio2(node) {
if (!node.name) {
return true;
}
- var radioScope = node.form || node.ownerDocument;
+ var radioScope = node.form || getRootNode(node);
var queryRadios = function queryRadios2(name) {
return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
};
var radioSet;
if (typeof window !== "undefined" && typeof window.CSS !== "undefined" && typeof window.CSS.escape === "function") {
@@ -10725,92 +10774,154 @@
return isInput(node) && node.type === "radio";
};
var isNonTabbableRadio = function isNonTabbableRadio2(node) {
return isRadio(node) && !isTabbableRadio(node);
};
- var isHidden = function isHidden2(node, displayCheck) {
+ var isZeroArea = function isZeroArea2(node) {
+ var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height;
+ return width === 0 && height === 0;
+ };
+ var isHidden = function isHidden2(node, _ref) {
+ var displayCheck = _ref.displayCheck, getShadowRoot = _ref.getShadowRoot;
if (getComputedStyle(node).visibility === "hidden") {
return true;
}
var isDirectSummary = matches.call(node, "details>summary:first-of-type");
var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
if (matches.call(nodeUnderDetails, "details:not([open]) *")) {
return true;
}
+ var nodeRootHost = getRootNode(node).host;
+ var nodeIsAttached = (nodeRootHost === null || nodeRootHost === void 0 ? void 0 : nodeRootHost.ownerDocument.contains(nodeRootHost)) || node.ownerDocument.contains(node);
if (!displayCheck || displayCheck === "full") {
- while (node) {
- if (getComputedStyle(node).display === "none") {
- return true;
+ if (typeof getShadowRoot === "function") {
+ var originalNode = node;
+ while (node) {
+ var parentElement = node.parentElement;
+ var rootNode = getRootNode(node);
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true) {
+ return isZeroArea(node);
+ } else if (node.assignedSlot) {
+ node = node.assignedSlot;
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
+ node = rootNode.host;
+ } else {
+ node = parentElement;
+ }
}
- node = node.parentElement;
+ node = originalNode;
}
+ if (nodeIsAttached) {
+ return !node.getClientRects().length;
+ }
} else if (displayCheck === "non-zero-area") {
- var _node$getBoundingClie = node.getBoundingClientRect(), width = _node$getBoundingClie.width, height = _node$getBoundingClie.height;
- return width === 0 && height === 0;
+ return isZeroArea(node);
}
return false;
};
var isDisabledFromFieldset = function isDisabledFromFieldset2(node) {
- if (isInput(node) || node.tagName === "SELECT" || node.tagName === "TEXTAREA" || node.tagName === "BUTTON") {
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
var parentNode = node.parentElement;
while (parentNode) {
if (parentNode.tagName === "FIELDSET" && parentNode.disabled) {
for (var i2 = 0; i2 < parentNode.children.length; i2++) {
var child = parentNode.children.item(i2);
if (child.tagName === "LEGEND") {
- if (child.contains(node)) {
- return false;
- }
- return true;
+ return matches.call(parentNode, "fieldset[disabled] *") ? true : !child.contains(node);
}
}
return true;
}
parentNode = parentNode.parentElement;
}
}
return false;
};
var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable2(options, node) {
- if (node.disabled || isHiddenInput(node) || isHidden(node, options.displayCheck) || isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
+ if (node.disabled || isHiddenInput(node) || isHidden(node, options) || // For a details element with a summary, the summary element gets the focus
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
return false;
}
return true;
};
var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable2(options, node) {
- if (!isNodeMatchingSelectorFocusable(options, node) || isNonTabbableRadio(node) || getTabindex(node) < 0) {
+ if (isNonTabbableRadio(node) || getTabindex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
return false;
}
return true;
};
- var tabbable = function tabbable2(el, options) {
- options = options || {};
+ var isValidShadowRootTabbable = function isValidShadowRootTabbable2(shadowHostNode) {
+ var tabIndex = parseInt(shadowHostNode.getAttribute("tabindex"), 10);
+ if (isNaN(tabIndex) || tabIndex >= 0) {
+ return true;
+ }
+ return false;
+ };
+ var sortByOrder = function sortByOrder2(candidates) {
var regularTabbables = [];
var orderedTabbables = [];
- var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
- candidates.forEach(function(candidate, i2) {
- var candidateTabindex = getTabindex(candidate);
+ candidates.forEach(function(item, i2) {
+ var isScope = !!item.scope;
+ var element = isScope ? item.scope : item;
+ var candidateTabindex = getTabindex(element, isScope);
+ var elements = isScope ? sortByOrder2(item.candidates) : element;
if (candidateTabindex === 0) {
- regularTabbables.push(candidate);
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
} else {
orderedTabbables.push({
documentOrder: i2,
tabIndex: candidateTabindex,
- node: candidate
+ item,
+ isScope,
+ content: elements
});
}
});
- var tabbableNodes = orderedTabbables.sort(sortOrderedTabbables).map(function(a2) {
- return a2.node;
- }).concat(regularTabbables);
- return tabbableNodes;
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function(acc, sortable) {
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
+ return acc;
+ }, []).concat(regularTabbables);
};
+ var tabbable = function tabbable2(el, options) {
+ options = options || {};
+ var candidates;
+ if (options.getShadowRoot) {
+ candidates = getCandidatesIteratively([el], options.includeContainer, {
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
+ flatten: false,
+ getShadowRoot: options.getShadowRoot,
+ shadowRootFilter: isValidShadowRootTabbable
+ });
+ } else {
+ candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
+ }
+ return sortByOrder(candidates);
+ };
var focusable = function focusable2(el, options) {
options = options || {};
- var candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
+ var candidates;
+ if (options.getShadowRoot) {
+ candidates = getCandidatesIteratively([el], options.includeContainer, {
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
+ flatten: true,
+ getShadowRoot: options.getShadowRoot
+ });
+ } else {
+ candidates = getCandidates(el, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
+ }
return candidates;
};
+ var isTabbable = function isTabbable2(node, options) {
+ options = options || {};
+ if (!node) {
+ throw new Error("No node provided");
+ }
+ if (matches.call(node, candidateSelector) === false) {
+ return false;
+ }
+ return isNodeMatchingSelectorTabbable(options, node);
+ };
var focusableCandidateSelector = /* @__PURE__ */ candidateSelectors.concat("iframe").join(",");
var isFocusable = function isFocusable2(node, options) {
options = options || {};
if (!node) {
throw new Error("No node provided");
@@ -10822,33 +10933,24 @@
};
function ownKeys2(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
- if (enumerableOnly) {
- symbols = symbols.filter(function(sym) {
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
- });
- }
- keys.push.apply(keys, symbols);
+ enumerableOnly && (symbols = symbols.filter(function(sym) {
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
+ })), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i2 = 1; i2 < arguments.length; i2++) {
- var source = arguments[i2] != null ? arguments[i2] : {};
- if (i2 % 2) {
- ownKeys2(Object(source), true).forEach(function(key) {
- _defineProperty(target, key, source[key]);
- });
- } else if (Object.getOwnPropertyDescriptors) {
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
- } else {
- ownKeys2(Object(source)).forEach(function(key) {
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
- });
- }
+ var source = null != arguments[i2] ? arguments[i2] : {};
+ i2 % 2 ? ownKeys2(Object(source), true).forEach(function(key) {
+ _defineProperty(target, key, source[key]);
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys2(Object(source)).forEach(function(key) {
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
+ });
}
return target;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
@@ -10919,88 +11021,153 @@
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
params[_key - 1] = arguments[_key];
}
return typeof value === "function" ? value.apply(void 0, params) : value;
};
+ var getActualTarget = function getActualTarget2(event) {
+ return event.target.shadowRoot && typeof event.composedPath === "function" ? event.composedPath()[0] : event.target;
+ };
var createFocusTrap = function createFocusTrap2(elements, userOptions) {
- var doc = document;
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
var config = _objectSpread2({
returnFocusOnDeactivate: true,
escapeDeactivates: true,
delayInitialFocus: true
}, userOptions);
var state = {
+ // containers given to createFocusTrap()
+ // @type {Array<HTMLElement>}
containers: [],
+ // list of objects identifying tabbable nodes in `containers` in the trap
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
+ // is active, but the trap should never get to a state where there isn't at least one group
+ // with at least one tabbable node in it (that would lead to an error condition that would
+ // result in an error being thrown)
+ // @type {Array<{
+ // container: HTMLElement,
+ // tabbableNodes: Array<HTMLElement>, // empty if none
+ // focusableNodes: Array<HTMLElement>, // empty if none
+ // firstTabbableNode: HTMLElement|null,
+ // lastTabbableNode: HTMLElement|null,
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
+ // }>}
+ containerGroups: [],
+ // same order/length as `containers` list
+ // references to objects in `containerGroups`, but only those that actually have
+ // tabbable nodes in them
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
+ // the same length
tabbableGroups: [],
nodeFocusedBeforeActivation: null,
mostRecentlyFocusedNode: null,
active: false,
paused: false,
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
+ // has been delayed during activation
delayInitialFocusTimer: void 0
};
var trap;
var getOption = function getOption2(configOverrideOptions, optionName, configOptionName) {
return configOverrideOptions && configOverrideOptions[optionName] !== void 0 ? configOverrideOptions[optionName] : config[configOptionName || optionName];
};
- var containersContain = function containersContain2(element) {
- return state.containers.some(function(container) {
- return container.contains(element);
+ var findContainerIndex = function findContainerIndex2(element) {
+ return state.containerGroups.findIndex(function(_ref) {
+ var container = _ref.container, tabbableNodes = _ref.tabbableNodes;
+ return container.contains(element) || // fall back to explicit tabbable search which will take into consideration any
+ // web components if the `tabbableOptions.getShadowRoot` option was used for
+ // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
+ // look inside web components even if open)
+ tabbableNodes.find(function(node) {
+ return node === element;
+ });
});
};
var getNodeForOption = function getNodeForOption2(optionName) {
var optionValue = config[optionName];
+ if (typeof optionValue === "function") {
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
+ params[_key2 - 1] = arguments[_key2];
+ }
+ optionValue = optionValue.apply(void 0, params);
+ }
+ if (optionValue === true) {
+ optionValue = void 0;
+ }
if (!optionValue) {
- return null;
+ if (optionValue === void 0 || optionValue === false) {
+ return optionValue;
+ }
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
}
var node = optionValue;
if (typeof optionValue === "string") {
node = doc.querySelector(optionValue);
if (!node) {
- throw new Error("`".concat(optionName, "` refers to no known node"));
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
}
}
- if (typeof optionValue === "function") {
- node = optionValue();
- if (!node) {
- throw new Error("`".concat(optionName, "` did not return a node"));
- }
- }
return node;
};
var getInitialFocusNode = function getInitialFocusNode2() {
- var node;
- if (getOption({}, "initialFocus") === false) {
+ var node = getNodeForOption("initialFocus");
+ if (node === false) {
return false;
}
- if (getNodeForOption("initialFocus") !== null) {
- node = getNodeForOption("initialFocus");
- } else if (containersContain(doc.activeElement)) {
- node = doc.activeElement;
- } else {
- var firstTabbableGroup = state.tabbableGroups[0];
- var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
- node = firstTabbableNode || getNodeForOption("fallbackFocus");
+ if (node === void 0) {
+ if (findContainerIndex(doc.activeElement) >= 0) {
+ node = doc.activeElement;
+ } else {
+ var firstTabbableGroup = state.tabbableGroups[0];
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
+ node = firstTabbableNode || getNodeForOption("fallbackFocus");
+ }
}
if (!node) {
throw new Error("Your focus-trap needs to have at least one focusable element");
}
return node;
};
var updateTabbableNodes = function updateTabbableNodes2() {
- state.tabbableGroups = state.containers.map(function(container) {
- var tabbableNodes = tabbable(container);
- if (tabbableNodes.length > 0) {
- return {
- container,
- firstTabbableNode: tabbableNodes[0],
- lastTabbableNode: tabbableNodes[tabbableNodes.length - 1]
- };
- }
- return void 0;
- }).filter(function(group) {
- return !!group;
+ state.containerGroups = state.containers.map(function(container) {
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
+ var focusableNodes = focusable(container, config.tabbableOptions);
+ return {
+ container,
+ tabbableNodes,
+ focusableNodes,
+ firstTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[0] : null,
+ lastTabbableNode: tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : null,
+ /**
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
+ * in this container, if any.
+ * @param {HTMLElement} node
+ * @param {boolean} [forward] True if going in forward tab order; false if going
+ * in reverse.
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
+ */
+ nextTabbableNode: function nextTabbableNode(node) {
+ var forward = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
+ var nodeIdx = focusableNodes.findIndex(function(n2) {
+ return n2 === node;
+ });
+ if (nodeIdx < 0) {
+ return void 0;
+ }
+ if (forward) {
+ return focusableNodes.slice(nodeIdx + 1).find(function(n2) {
+ return isTabbable(n2, config.tabbableOptions);
+ });
+ }
+ return focusableNodes.slice(0, nodeIdx).reverse().find(function(n2) {
+ return isTabbable(n2, config.tabbableOptions);
+ });
+ }
+ };
});
+ state.tabbableGroups = state.containerGroups.filter(function(group) {
+ return group.tabbableNodes.length > 0;
+ });
if (state.tabbableGroups.length <= 0 && !getNodeForOption("fallbackFocus")) {
throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");
}
};
var tryFocus = function tryFocus2(node) {
@@ -11021,72 +11188,84 @@
if (isSelectableInput(node)) {
node.select();
}
};
var getReturnFocusNode = function getReturnFocusNode2(previousActiveElement) {
- var node = getNodeForOption("setReturnFocus");
- return node ? node : previousActiveElement;
+ var node = getNodeForOption("setReturnFocus", previousActiveElement);
+ return node ? node : node === false ? false : previousActiveElement;
};
var checkPointerDown = function checkPointerDown2(e2) {
- if (containersContain(e2.target)) {
+ var target = getActualTarget(e2);
+ if (findContainerIndex(target) >= 0) {
return;
}
if (valueOrHandler(config.clickOutsideDeactivates, e2)) {
trap.deactivate({
- returnFocus: config.returnFocusOnDeactivate && !isFocusable(e2.target)
+ // if, on deactivation, we should return focus to the node originally-focused
+ // when the trap was activated (or the configured `setReturnFocus` node),
+ // then assume it's also OK to return focus to the outside node that was
+ // just clicked, causing deactivation, as long as that node is focusable;
+ // if it isn't focusable, then return focus to the original node focused
+ // on activation (or the configured `setReturnFocus` node)
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
+ // which will result in the outside click setting focus to the node
+ // that was clicked, whether it's focusable or not; by setting
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
+ // on activation (or the configured `setReturnFocus` node)
+ returnFocus: config.returnFocusOnDeactivate && !isFocusable(target, config.tabbableOptions)
});
return;
}
if (valueOrHandler(config.allowOutsideClick, e2)) {
return;
}
e2.preventDefault();
};
var checkFocusIn = function checkFocusIn2(e2) {
- var targetContained = containersContain(e2.target);
- if (targetContained || e2.target instanceof Document) {
+ var target = getActualTarget(e2);
+ var targetContained = findContainerIndex(target) >= 0;
+ if (targetContained || target instanceof Document) {
if (targetContained) {
- state.mostRecentlyFocusedNode = e2.target;
+ state.mostRecentlyFocusedNode = target;
}
} else {
e2.stopImmediatePropagation();
tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
}
};
var checkTab = function checkTab2(e2) {
+ var target = getActualTarget(e2);
updateTabbableNodes();
var destinationNode = null;
if (state.tabbableGroups.length > 0) {
- var containerIndex = findIndex(state.tabbableGroups, function(_ref) {
- var container = _ref.container;
- return container.contains(e2.target);
- });
+ var containerIndex = findContainerIndex(target);
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : void 0;
if (containerIndex < 0) {
if (e2.shiftKey) {
destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
} else {
destinationNode = state.tabbableGroups[0].firstTabbableNode;
}
} else if (e2.shiftKey) {
var startOfGroupIndex = findIndex(state.tabbableGroups, function(_ref2) {
var firstTabbableNode = _ref2.firstTabbableNode;
- return e2.target === firstTabbableNode;
+ return target === firstTabbableNode;
});
- if (startOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e2.target) {
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
startOfGroupIndex = containerIndex;
}
if (startOfGroupIndex >= 0) {
var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
var destinationGroup = state.tabbableGroups[destinationGroupIndex];
destinationNode = destinationGroup.lastTabbableNode;
}
} else {
var lastOfGroupIndex = findIndex(state.tabbableGroups, function(_ref3) {
var lastTabbableNode = _ref3.lastTabbableNode;
- return e2.target === lastTabbableNode;
+ return target === lastTabbableNode;
});
- if (lastOfGroupIndex < 0 && state.tabbableGroups[containerIndex].container === e2.target) {
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
lastOfGroupIndex = containerIndex;
}
if (lastOfGroupIndex >= 0) {
var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
@@ -11100,25 +11279,26 @@
e2.preventDefault();
tryFocus(destinationNode);
}
};
var checkKey = function checkKey2(e2) {
- if (isEscapeEvent(e2) && valueOrHandler(config.escapeDeactivates) !== false) {
+ if (isEscapeEvent(e2) && valueOrHandler(config.escapeDeactivates, e2) !== false) {
e2.preventDefault();
trap.deactivate();
return;
}
if (isTabEvent(e2)) {
checkTab(e2);
return;
}
};
var checkClick = function checkClick2(e2) {
- if (valueOrHandler(config.clickOutsideDeactivates, e2)) {
+ var target = getActualTarget(e2);
+ if (findContainerIndex(target) >= 0) {
return;
}
- if (containersContain(e2.target)) {
+ if (valueOrHandler(config.clickOutsideDeactivates, e2)) {
return;
}
if (valueOrHandler(config.allowOutsideClick, e2)) {
return;
}
@@ -11162,10 +11342,16 @@
doc.removeEventListener("click", checkClick, true);
doc.removeEventListener("keydown", checkKey, true);
return trap;
};
trap = {
+ get active() {
+ return state.active;
+ },
+ get paused() {
+ return state.paused;
+ },
activate: function activate(activateOptions) {
if (state.active) {
return this;
}
var onActivate = getOption(activateOptions, "onActivate");
@@ -11198,23 +11384,28 @@
},
deactivate: function deactivate(deactivateOptions) {
if (!state.active) {
return this;
}
+ var options = _objectSpread2({
+ onDeactivate: config.onDeactivate,
+ onPostDeactivate: config.onPostDeactivate,
+ checkCanReturnFocus: config.checkCanReturnFocus
+ }, deactivateOptions);
clearTimeout(state.delayInitialFocusTimer);
state.delayInitialFocusTimer = void 0;
removeListeners();
state.active = false;
state.paused = false;
activeFocusTraps.deactivateTrap(trap);
- var onDeactivate = getOption(deactivateOptions, "onDeactivate");
- var onPostDeactivate = getOption(deactivateOptions, "onPostDeactivate");
- var checkCanReturnFocus = getOption(deactivateOptions, "checkCanReturnFocus");
+ var onDeactivate = getOption(options, "onDeactivate");
+ var onPostDeactivate = getOption(options, "onPostDeactivate");
+ var checkCanReturnFocus = getOption(options, "checkCanReturnFocus");
+ var returnFocus = getOption(options, "returnFocus", "returnFocusOnDeactivate");
if (onDeactivate) {
onDeactivate();
}
- var returnFocus = getOption(deactivateOptions, "returnFocus", "returnFocusOnDeactivate");
var finishDeactivation = function finishDeactivation2() {
delay(function() {
if (returnFocus) {
tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
}
@@ -11370,59 +11561,65 @@
el2.focus({ preventScroll: this._noscroll });
});
}
};
});
- Alpine3.directive("trap", Alpine3.skipDuringClone((el, { expression, modifiers }, { effect: effect7, evaluateLater: evaluateLater2, cleanup: cleanup2 }) => {
- let evaluator = evaluateLater2(expression);
- let oldValue = false;
- let options = {
- escapeDeactivates: false,
- allowOutsideClick: true,
- fallbackFocus: () => el
- };
- let autofocusEl = el.querySelector("[autofocus]");
- if (autofocusEl)
- options.initialFocus = autofocusEl;
- let trap = createFocusTrap(el, options);
- let undoInert = () => {
- };
- let undoDisableScrolling = () => {
- };
- const releaseFocus = () => {
- undoInert();
- undoInert = () => {
+ Alpine3.directive("trap", Alpine3.skipDuringClone(
+ (el, { expression, modifiers }, { effect: effect7, evaluateLater: evaluateLater2, cleanup: cleanup2 }) => {
+ let evaluator = evaluateLater2(expression);
+ let oldValue = false;
+ let options = {
+ escapeDeactivates: false,
+ allowOutsideClick: true,
+ fallbackFocus: () => el
};
- undoDisableScrolling();
- undoDisableScrolling = () => {
+ let autofocusEl = el.querySelector("[autofocus]");
+ if (autofocusEl)
+ options.initialFocus = autofocusEl;
+ let trap = createFocusTrap(el, options);
+ let undoInert = () => {
};
- trap.deactivate({
- returnFocus: !modifiers.includes("noreturn")
- });
- };
- effect7(() => evaluator((value) => {
- if (oldValue === value)
- return;
- if (value && !oldValue) {
- setTimeout(() => {
- if (modifiers.includes("inert"))
- undoInert = setInert(el);
- if (modifiers.includes("noscroll"))
- undoDisableScrolling = disableScrolling();
- trap.activate();
+ let undoDisableScrolling = () => {
+ };
+ const releaseFocus = () => {
+ undoInert();
+ undoInert = () => {
+ };
+ undoDisableScrolling();
+ undoDisableScrolling = () => {
+ };
+ trap.deactivate({
+ returnFocus: !modifiers.includes("noreturn")
});
- }
- if (!value && oldValue) {
- releaseFocus();
- }
- oldValue = !!value;
- }));
- cleanup2(releaseFocus);
- }, (el, { expression, modifiers }, { evaluate: evaluate2 }) => {
- if (modifiers.includes("inert") && evaluate2(expression))
- setInert(el);
- }));
+ };
+ effect7(() => evaluator((value) => {
+ if (oldValue === value)
+ return;
+ if (value && !oldValue) {
+ setTimeout(() => {
+ if (modifiers.includes("inert"))
+ undoInert = setInert(el);
+ if (modifiers.includes("noscroll"))
+ undoDisableScrolling = disableScrolling();
+ trap.activate();
+ });
+ }
+ if (!value && oldValue) {
+ releaseFocus();
+ }
+ oldValue = !!value;
+ }));
+ cleanup2(releaseFocus);
+ },
+ // When cloning, we only want to add aria-hidden attributes to the
+ // DOM and not try to actually trap, as trapping can mess with the
+ // live DOM and isn't just isolated to the cloned DOM.
+ (el, { expression, modifiers }, { evaluate: evaluate2 }) => {
+ if (modifiers.includes("inert") && evaluate2(expression))
+ setInert(el);
+ }
+ ));
}
function setInert(el) {
let undos = [];
crawlSiblingsUp(el, (sibling) => {
let cache = sibling.hasAttribute("aria-hidden");
@@ -15388,14 +15585,20 @@
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*)
@alpinejs/focus/dist/module.esm.js:
- (*!
- * tabbable 5.2.1
- * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
- *)
- (*!
- * focus-trap 6.6.1
- * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
+ (*! Bundled license information:
+
+ tabbable/dist/index.esm.js:
+ (*!
+ * tabbable 5.3.3
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
+ *)
+
+ focus-trap/dist/focus-trap.esm.js:
+ (*!
+ * focus-trap 6.9.4
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
+ *)
*)
*/