27 lines
850 B
JavaScript
27 lines
850 B
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
var array_1 = require("./array");
|
|
exports.tabSort = function (a, b) {
|
|
var tabDiff = a.tabIndex - b.tabIndex;
|
|
var indexDiff = a.index - b.index;
|
|
if (tabDiff) {
|
|
if (!a.tabIndex) {
|
|
return 1;
|
|
}
|
|
if (!b.tabIndex) {
|
|
return -1;
|
|
}
|
|
}
|
|
return tabDiff || indexDiff;
|
|
};
|
|
exports.orderByTabIndex = function (nodes, filterNegative, keepGuards) {
|
|
return array_1.toArray(nodes)
|
|
.map(function (node, index) { return ({
|
|
node: node,
|
|
index: index,
|
|
tabIndex: keepGuards && node.tabIndex === -1 ? ((node.dataset || {}).focusGuard ? 0 : -1) : node.tabIndex,
|
|
}); })
|
|
.filter(function (data) { return !filterNegative || data.tabIndex >= 0; })
|
|
.sort(exports.tabSort);
|
|
};
|