source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/util/isNonInteractiveElement.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 7.4 KB
RevLine 
[9af201e]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7var _ariaQuery = require("aria-query");
8var _axobjectQuery = require("axobject-query");
9var _arrayIncludes = _interopRequireDefault(require("array-includes"));
10var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
11var _attributesComparator = _interopRequireDefault(require("./attributesComparator"));
12function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
13function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
14function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
17function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
18function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
20function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
21function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
22function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
23var roleKeys = _ariaQuery.roles.keys();
24var elementRoleEntries = _toConsumableArray(_ariaQuery.elementRoles);
25var nonInteractiveRoles = new Set(roleKeys.filter(function (name) {
26 var role = _ariaQuery.roles.get(name);
27 return !role["abstract"]
28 // 'toolbar' does not descend from widget, but it does support
29 // aria-activedescendant, thus in practice we treat it as a widget.
30 && name !== 'toolbar'
31 // This role is meant to have no semantic value.
32 // @see https://www.w3.org/TR/wai-aria-1.2/#generic
33 && name !== 'generic' && !role.superClass.some(function (classes) {
34 return (0, _arrayIncludes["default"])(classes, 'widget');
35 });
36}).concat(
37// The `progressbar` is descended from `widget`, but in practice, its
38// value is always `readonly`, so we treat it as a non-interactive role.
39'progressbar'));
40var interactiveRoles = new Set(roleKeys.filter(function (name) {
41 var role = _ariaQuery.roles.get(name);
42 return !role["abstract"]
43 // The `progressbar` is descended from `widget`, but in practice, its
44 // value is always `readonly`, so we treat it as a non-interactive role.
45 && name !== 'progressbar'
46 // This role is meant to have no semantic value.
47 // @see https://www.w3.org/TR/wai-aria-1.2/#generic
48 && name !== 'generic' && role.superClass.some(function (classes) {
49 return (0, _arrayIncludes["default"])(classes, 'widget');
50 });
51}).concat(
52// 'toolbar' does not descend from widget, but it does support
53// aria-activedescendant, thus in practice we treat it as a widget.
54'toolbar'));
55var interactiveElementRoleSchemas = (0, _arrayPrototype["default"])(elementRoleEntries, function (_ref) {
56 var _ref2 = _slicedToArray(_ref, 2),
57 elementSchema = _ref2[0],
58 rolesArr = _ref2[1];
59 return rolesArr.some(function (role) {
60 return interactiveRoles.has(role);
61 }) ? [elementSchema] : [];
62});
63var nonInteractiveElementRoleSchemas = (0, _arrayPrototype["default"])(elementRoleEntries, function (_ref3) {
64 var _ref4 = _slicedToArray(_ref3, 2),
65 elementSchema = _ref4[0],
66 rolesArr = _ref4[1];
67 return rolesArr.every(function (role) {
68 return nonInteractiveRoles.has(role);
69 }) ? [elementSchema] : [];
70});
71var nonInteractiveAXObjects = new Set(_axobjectQuery.AXObjects.keys().filter(function (name) {
72 return (0, _arrayIncludes["default"])(['window', 'structure'], _axobjectQuery.AXObjects.get(name).type);
73}));
74var nonInteractiveElementAXObjectSchemas = (0, _arrayPrototype["default"])(_toConsumableArray(_axobjectQuery.elementAXObjects), function (_ref5) {
75 var _ref6 = _slicedToArray(_ref5, 2),
76 elementSchema = _ref6[0],
77 AXObjectsArr = _ref6[1];
78 return AXObjectsArr.every(function (role) {
79 return nonInteractiveAXObjects.has(role);
80 }) ? [elementSchema] : [];
81});
82function checkIsNonInteractiveElement(tagName, attributes) {
83 function elementSchemaMatcher(elementSchema) {
84 return tagName === elementSchema.name && tagName !== 'td' // TODO: investigate why this is needed
85 && (0, _attributesComparator["default"])(elementSchema.attributes, attributes);
86 }
87 // Check in elementRoles for inherent non-interactive role associations for
88 // this element.
89 var isInherentNonInteractiveElement = nonInteractiveElementRoleSchemas.some(elementSchemaMatcher);
90 if (isInherentNonInteractiveElement) {
91 return true;
92 }
93 // Check in elementRoles for inherent interactive role associations for
94 // this element.
95 var isInherentInteractiveElement = interactiveElementRoleSchemas.some(elementSchemaMatcher);
96 if (isInherentInteractiveElement) {
97 return false;
98 }
99 // Check in elementAXObjects for AX Tree associations for this element.
100 var isNonInteractiveAXElement = nonInteractiveElementAXObjectSchemas.some(elementSchemaMatcher);
101 if (isNonInteractiveAXElement) {
102 return true;
103 }
104 return false;
105}
106
107/**
108 * Returns boolean indicating whether the given element is a non-interactive
109 * element. If the element has either a non-interactive role assigned or it
110 * is an element with an inherently non-interactive role, then this utility
111 * returns true. Elements that lack either an explicitly assigned role or
112 * an inherent role are not considered. For those, this utility returns false
113 * because a positive determination of interactiveness cannot be determined.
114 */
115var isNonInteractiveElement = function isNonInteractiveElement(tagName, attributes) {
116 // Do not test higher level JSX components, as we do not know what
117 // low-level DOM element this maps to.
118 if (!_ariaQuery.dom.has(tagName)) {
119 return false;
120 }
121 // <header> elements do not technically have semantics, unless the
122 // element is a direct descendant of <body>, and this plugin cannot
123 // reliably test that.
124 // @see https://www.w3.org/TR/wai-aria-practices/examples/landmarks/banner.html
125 if (tagName === 'header') {
126 return false;
127 }
128 return checkIsNonInteractiveElement(tagName, attributes);
129};
130var _default = exports["default"] = isNonInteractiveElement;
131module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.