@salutejs/plasma-new-hope 0.116.1-canary.1345.10274146329.0 → 0.116.1-canary.1346.10269858402.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/cjs/components/Modal/Modal.js +1 -3
  2. package/cjs/components/Modal/Modal.js.map +1 -1
  3. package/cjs/index.js +0 -2
  4. package/cjs/index.js.map +1 -1
  5. package/emotion/cjs/components/Modal/Modal.js +3 -4
  6. package/emotion/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -115
  7. package/emotion/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -115
  8. package/emotion/cjs/hooks/index.js +0 -7
  9. package/emotion/es/components/Modal/Modal.js +2 -3
  10. package/emotion/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -115
  11. package/emotion/es/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -115
  12. package/emotion/es/hooks/index.js +0 -1
  13. package/es/components/Modal/Modal.js +2 -4
  14. package/es/components/Modal/Modal.js.map +1 -1
  15. package/es/index.js +0 -1
  16. package/es/index.js.map +1 -1
  17. package/package.json +4 -4
  18. package/styled-components/cjs/components/Modal/Modal.js +3 -4
  19. package/styled-components/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -115
  20. package/styled-components/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -115
  21. package/styled-components/cjs/hooks/index.js +0 -7
  22. package/styled-components/es/components/Modal/Modal.js +2 -3
  23. package/styled-components/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -115
  24. package/styled-components/es/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -115
  25. package/styled-components/es/hooks/index.js +0 -1
  26. package/types/components/Modal/Modal.d.ts.map +1 -1
  27. package/types/hooks/index.d.ts +0 -1
  28. package/types/hooks/index.d.ts.map +1 -1
  29. package/cjs/hooks/useFocusTrap.js +0 -97
  30. package/cjs/hooks/useFocusTrap.js.map +0 -1
  31. package/cjs/utils/focusManager.js +0 -56
  32. package/cjs/utils/focusManager.js.map +0 -1
  33. package/cjs/utils/scopeTab.js +0 -37
  34. package/cjs/utils/scopeTab.js.map +0 -1
  35. package/cjs/utils/tabbable.js +0 -51
  36. package/cjs/utils/tabbable.js.map +0 -1
  37. package/emotion/cjs/hooks/useFocusTrap.js +0 -95
  38. package/emotion/cjs/utils/focusManager.js +0 -60
  39. package/emotion/cjs/utils/scopeTab.js +0 -35
  40. package/emotion/cjs/utils/tabbable.js +0 -46
  41. package/emotion/cjs/utils/useFocusTrap.js +0 -95
  42. package/emotion/es/hooks/useFocusTrap.js +0 -90
  43. package/emotion/es/utils/focusManager.js +0 -55
  44. package/emotion/es/utils/scopeTab.js +0 -30
  45. package/emotion/es/utils/tabbable.js +0 -40
  46. package/emotion/es/utils/useFocusTrap.js +0 -90
  47. package/es/hooks/useFocusTrap.js +0 -93
  48. package/es/hooks/useFocusTrap.js.map +0 -1
  49. package/es/utils/focusManager.js +0 -52
  50. package/es/utils/focusManager.js.map +0 -1
  51. package/es/utils/scopeTab.js +0 -33
  52. package/es/utils/scopeTab.js.map +0 -1
  53. package/es/utils/tabbable.js +0 -43
  54. package/es/utils/tabbable.js.map +0 -1
  55. package/styled-components/cjs/hooks/useFocusTrap.js +0 -95
  56. package/styled-components/cjs/utils/focusManager.js +0 -60
  57. package/styled-components/cjs/utils/scopeTab.js +0 -35
  58. package/styled-components/cjs/utils/tabbable.js +0 -46
  59. package/styled-components/cjs/utils/useFocusTrap.js +0 -95
  60. package/styled-components/es/hooks/useFocusTrap.js +0 -90
  61. package/styled-components/es/utils/focusManager.js +0 -55
  62. package/styled-components/es/utils/scopeTab.js +0 -30
  63. package/styled-components/es/utils/tabbable.js +0 -40
  64. package/styled-components/es/utils/useFocusTrap.js +0 -90
  65. package/types/hooks/useFocusTrap.d.ts +0 -6
  66. package/types/hooks/useFocusTrap.d.ts.map +0 -1
  67. package/types/utils/focusManager.d.ts +0 -15
  68. package/types/utils/focusManager.d.ts.map +0 -1
  69. package/types/utils/scopeTab.d.ts +0 -7
  70. package/types/utils/scopeTab.d.ts.map +0 -1
  71. package/types/utils/tabbable.d.ts +0 -6
  72. package/types/utils/tabbable.d.ts.map +0 -1
  73. package/types/utils/useFocusTrap.d.ts +0 -6
  74. package/types/utils/useFocusTrap.d.ts.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"scopeTab.js","sources":["../../src/utils/scopeTab.ts"],"sourcesContent":["import { findTabbableDescendants } from './tabbable';\n\n/**\n * Управлление фокусом лишь внутри ноды через tab\n * @param node\n * @param event\n */\nexport const scopeTab = (node: HTMLElement, event: KeyboardEvent) => {\n const tabbable = findTabbableDescendants(node);\n if (!tabbable.length) {\n event.preventDefault();\n return;\n }\n\n // смотрим, является ли элемент крайним - первый или последним\n const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];\n const leavingFinalTabbable = finalTabbable === document.activeElement || node === document.activeElement;\n\n // если не является, то передаем обработку таба самому браузеру\n if (!leavingFinalTabbable) {\n return;\n }\n\n // иначе зацкливаемся\n event.preventDefault();\n const target = tabbable[event.shiftKey ? tabbable.length - 1 : 0];\n if (target) {\n target.focus();\n }\n};\n"],"names":["scopeTab","node","event","tabbable","findTabbableDescendants","length","preventDefault","finalTabbable","shiftKey","leavingFinalTabbable","document","activeElement","target","focus"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACO,IAAMA,QAAQ,GAAG,SAAXA,QAAQA,CAAIC,IAAiB,EAAEC,KAAoB,EAAK;AACjE,EAAA,IAAMC,QAAQ,GAAGC,uBAAuB,CAACH,IAAI,CAAC,CAAA;AAC9C,EAAA,IAAI,CAACE,QAAQ,CAACE,MAAM,EAAE;IAClBH,KAAK,CAACI,cAAc,EAAE,CAAA;AACtB,IAAA,OAAA;AACJ,GAAA;;AAEA;AACA,EAAA,IAAMC,aAAa,GAAGJ,QAAQ,CAACD,KAAK,CAACM,QAAQ,GAAG,CAAC,GAAGL,QAAQ,CAACE,MAAM,GAAG,CAAC,CAAC,CAAA;AACxE,EAAA,IAAMI,oBAAoB,GAAGF,aAAa,KAAKG,QAAQ,CAACC,aAAa,IAAIV,IAAI,KAAKS,QAAQ,CAACC,aAAa,CAAA;;AAExG;EACA,IAAI,CAACF,oBAAoB,EAAE;AACvB,IAAA,OAAA;AACJ,GAAA;;AAEA;EACAP,KAAK,CAACI,cAAc,EAAE,CAAA;AACtB,EAAA,IAAMM,MAAM,GAAGT,QAAQ,CAACD,KAAK,CAACM,QAAQ,GAAGL,QAAQ,CAACE,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;AACjE,EAAA,IAAIO,MAAM,EAAE;IACRA,MAAM,CAACC,KAAK,EAAE,CAAA;AAClB,GAAA;AACJ;;;;"}
@@ -1,43 +0,0 @@
1
- var tabbableNode = /input|select|textarea|button|object/;
2
- var focusSelector = /*#__PURE__*/['input', 'select', 'textarea', 'a', 'button', 'object', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'].join(',');
3
- var isHidden = function isHidden(el) {
4
- return el.offsetWidth <= 0 && el.offsetHeight <= 0 || el.style.display === 'none' || el.style.visibility === 'hidden' || el.style.opacity === '0';
5
- };
6
- var isVisible = function isVisible(element, parentContainer) {
7
- var parentElement = element;
8
- while (parentElement) {
9
- if (parentElement === parentContainer || parentElement === document.body) {
10
- break;
11
- }
12
- if (isHidden(parentElement)) {
13
- return false;
14
- }
15
- parentElement = parentElement.parentNode;
16
- }
17
- return true;
18
- };
19
- var getElementTabIndex = function getElementTabIndex(element) {
20
- var tabIndex = element.getAttribute('tabindex');
21
- return tabIndex === null ? NaN : parseInt(tabIndex, 10);
22
- };
23
- var isFocusable = function isFocusable(element, parentContainer) {
24
- var nodeName = element.nodeName.toLowerCase();
25
- var isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
26
- var res = tabbableNode.test(nodeName) && !element.disabled || (element instanceof HTMLAnchorElement ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);
27
- return Boolean(res) && isVisible(element, parentContainer);
28
- };
29
- var isTabble = function isTabble(element, parentContainer) {
30
- var tabIndex = getElementTabIndex(element);
31
- var isTabIndexNaN = Number.isNaN(tabIndex);
32
- return (isTabIndexNaN || tabIndex >= 0) && isFocusable(element, parentContainer);
33
- };
34
-
35
- // Все элементы внутри данной ноды, до которых можно добраться табом
36
- var findTabbableDescendants = function findTabbableDescendants(element) {
37
- return Array.from(element.querySelectorAll(focusSelector)).filter(function (el) {
38
- return isTabble(el, element);
39
- });
40
- };
41
-
42
- export { findTabbableDescendants, focusSelector, isFocusable, isTabble, isVisible };
43
- //# sourceMappingURL=tabbable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tabbable.js","sources":["../../src/utils/tabbable.ts"],"sourcesContent":["const tabbableNode = /input|select|textarea|button|object/;\n\nexport const focusSelector = [\n 'input',\n 'select',\n 'textarea',\n 'a',\n 'button',\n 'object',\n '[tabindex]',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n].join(',');\n\nconst isHidden = (el: HTMLElement) => {\n return (\n (el.offsetWidth <= 0 && el.offsetHeight <= 0) ||\n el.style.display === 'none' ||\n el.style.visibility === 'hidden' ||\n el.style.opacity === '0'\n );\n};\n\nexport const isVisible = (element: HTMLElement, parentContainer?: HTMLElement): boolean => {\n let parentElement: HTMLElement = element;\n\n while (parentElement) {\n if (parentElement === parentContainer || parentElement === document.body) {\n break;\n }\n\n if (isHidden(parentElement)) {\n return false;\n }\n\n parentElement = parentElement.parentNode as HTMLElement;\n }\n\n return true;\n};\n\nconst getElementTabIndex = (element: HTMLElement): number => {\n const tabIndex = element.getAttribute('tabindex');\n\n return tabIndex === null ? NaN : parseInt(tabIndex as string, 10);\n};\n\nexport const isFocusable = (element: HTMLElement, parentContainer?: HTMLElement): boolean => {\n const nodeName = element.nodeName.toLowerCase();\n const isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));\n const res =\n (tabbableNode.test(nodeName) && !(element as HTMLSelectElement).disabled) ||\n (element instanceof HTMLAnchorElement ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);\n\n return Boolean(res) && isVisible(element, parentContainer);\n};\n\nexport const isTabble = (element: HTMLElement, parentContainer?: HTMLElement): boolean => {\n const tabIndex = getElementTabIndex(element);\n const isTabIndexNaN = Number.isNaN(tabIndex);\n return (isTabIndexNaN || tabIndex >= 0) && isFocusable(element, parentContainer);\n};\n\n// Все элементы внутри данной ноды, до которых можно добраться табом\nexport const findTabbableDescendants = (element: HTMLElement): Array<HTMLElement> => {\n return Array.from(element.querySelectorAll<HTMLElement>(focusSelector)).filter((el) => isTabble(el, element));\n};\n"],"names":["tabbableNode","focusSelector","join","isHidden","el","offsetWidth","offsetHeight","style","display","visibility","opacity","isVisible","element","parentContainer","parentElement","document","body","parentNode","getElementTabIndex","tabIndex","getAttribute","NaN","parseInt","isFocusable","nodeName","toLowerCase","isTabIndexNotNaN","Number","isNaN","res","test","disabled","HTMLAnchorElement","href","Boolean","isTabble","isTabIndexNaN","findTabbableDescendants","Array","from","querySelectorAll","filter"],"mappings":"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"}
@@ -1,95 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useFocusTrap = void 0;
7
- var _react = /*#__PURE__*/require("react");
8
- var _focusManager = /*#__PURE__*/require("../utils/focusManager");
9
- var _tabbable = /*#__PURE__*/require("../utils/tabbable");
10
- var _scopeTab = /*#__PURE__*/require("../utils/scopeTab");
11
- // Находим элемент для фокуса
12
- var getFocusElement = function getFocusElement(node, firstFocusSelector) {
13
- var focusElement = null;
14
- if (firstFocusSelector) {
15
- if (typeof firstFocusSelector === 'string') {
16
- focusElement = node.querySelector(firstFocusSelector);
17
- } else if (firstFocusSelector.current) {
18
- focusElement = firstFocusSelector.current;
19
- }
20
- }
21
- if (!focusElement) {
22
- var children = Array.from(node.querySelectorAll(_tabbable.focusSelector));
23
- focusElement = children.find(function (el) {
24
- return (0, _tabbable.isTabble)(el);
25
- }) || null;
26
- }
27
-
28
- // Если ничего не нашлось, то может ли сама нода быть под фокусом
29
- if (!focusElement && (0, _tabbable.isFocusable)(node)) {
30
- focusElement = node;
31
- }
32
- return focusElement;
33
- };
34
- var processNode = function processNode(node, firstFocusSelector, ref) {
35
- if (ref !== null && ref !== void 0 && ref.current) {
36
- ref.current.removeEventListener('animationend', function () {
37
- processNode(node, firstFocusSelector, ref);
38
- });
39
- }
40
- var focusElement = getFocusElement(node, firstFocusSelector);
41
- if (focusElement) {
42
- focusElement.focus();
43
- }
44
- };
45
- var focusManager = /*#__PURE__*/new _focusManager.FocusManager();
46
-
47
- /**
48
- * Захватывает фокус внутри DOM node.
49
- * */
50
- var useFocusTrap = exports.useFocusTrap = function useFocusTrap() {
51
- var active = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
52
- var firstFocusSelector = arguments.length > 1 ? arguments[1] : undefined;
53
- var focusAfterNode = arguments.length > 2 ? arguments[2] : undefined;
54
- var activeAfterAnimation = arguments.length > 3 ? arguments[3] : undefined;
55
- var ref = (0, _react.useRef)();
56
- var setRef = (0, _react.useCallback)(function (node) {
57
- if (ref.current) {
58
- focusManager.teardownScopedFocus();
59
- focusManager.returnFocus();
60
- }
61
- if (active && node) {
62
- focusManager.setupScopedFocus(node);
63
- focusManager.markForFocusAfter(focusAfterNode);
64
-
65
- // Delay processing the HTML node by a frame. This ensures focus is assigned correctly.
66
- setTimeout(function () {
67
- if (ref !== null && ref !== void 0 && ref.current && node.ownerDocument && activeAfterAnimation) {
68
- ref.current.addEventListener('animationend', function () {
69
- processNode(node, firstFocusSelector, ref);
70
- });
71
- } else if (node.ownerDocument) {
72
- processNode(node, firstFocusSelector);
73
- }
74
- });
75
- ref.current = node;
76
- return;
77
- }
78
- ref.current = null;
79
- }, [active, firstFocusSelector]);
80
- (0, _react.useEffect)(function () {
81
- if (!active) {
82
- return;
83
- }
84
- var handleKeyDown = function handleKeyDown(event) {
85
- if (event.key === 'Tab' && ref.current) {
86
- (0, _scopeTab.scopeTab)(ref.current, event);
87
- }
88
- };
89
- document.addEventListener('keydown', handleKeyDown);
90
- return function () {
91
- document.removeEventListener('keydown', handleKeyDown);
92
- };
93
- }, [active]);
94
- return setRef;
95
- };
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FocusManager = void 0;
7
- var _tabbable = /*#__PURE__*/require("./tabbable");
8
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
11
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
- /**
16
- * Менеджер фокуса при открытии и закрытии нод при использовании focus-trap.
17
- * Также необходим, чтобы фокус всегда должен находиться внутри необходимой ноды.
18
- * */
19
- var FocusManager = exports.FocusManager = /*#__PURE__*/_createClass(function FocusManager() {
20
- var _this = this;
21
- _classCallCheck(this, FocusManager);
22
- // массив с элементами, которые нужно зафокусить после анмаунта
23
- _defineProperty(this, "focusAfterElements", []);
24
- // массив с trap нодами
25
- _defineProperty(this, "focusNodes", []);
26
- _defineProperty(this, "handleFocus", function () {
27
- // Фокус всегда должен находиться внутри необходимой ноды
28
- var focusNode = _this.focusNodes[_this.focusNodes.length - 1];
29
- if (!focusNode || focusNode.contains(document.activeElement)) {
30
- return;
31
- }
32
-
33
- // Выделяем первый tabbable элемент
34
- var el = (0, _tabbable.findTabbableDescendants)(focusNode)[0] || focusNode;
35
- el.focus();
36
- });
37
- // добавление на фокус после анмаунта
38
- _defineProperty(this, "markForFocusAfter", function (focusAfterNode) {
39
- var node = focusAfterNode && focusAfterNode.current ? focusAfterNode.current : document.activeElement;
40
- _this.focusAfterElements.push(node);
41
- });
42
- // фокус на необходимый элемент
43
- _defineProperty(this, "returnFocus", function () {
44
- var _this$focusAfterEleme;
45
- var toFocus = (_this$focusAfterEleme = _this.focusAfterElements.pop()) !== null && _this$focusAfterEleme !== void 0 ? _this$focusAfterEleme : null;
46
- if (toFocus) {
47
- toFocus.focus();
48
- }
49
- });
50
- // при маунте ноды
51
- _defineProperty(this, "setupScopedFocus", function (element) {
52
- _this.focusNodes.push(element);
53
- document.addEventListener('focusin', _this.handleFocus, true);
54
- });
55
- // при анмаунте
56
- _defineProperty(this, "teardownScopedFocus", function () {
57
- _this.focusNodes.pop();
58
- document.removeEventListener('focusin', _this.handleFocus);
59
- });
60
- });
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.scopeTab = void 0;
7
- var _tabbable = /*#__PURE__*/require("./tabbable");
8
- /**
9
- * Управлление фокусом лишь внутри ноды через tab
10
- * @param node
11
- * @param event
12
- */
13
- var scopeTab = exports.scopeTab = function scopeTab(node, event) {
14
- var tabbable = (0, _tabbable.findTabbableDescendants)(node);
15
- if (!tabbable.length) {
16
- event.preventDefault();
17
- return;
18
- }
19
-
20
- // смотрим, является ли элемент крайним - первый или последним
21
- var finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
22
- var leavingFinalTabbable = finalTabbable === document.activeElement || node === document.activeElement;
23
-
24
- // если не является, то передаем обработку таба самому браузеру
25
- if (!leavingFinalTabbable) {
26
- return;
27
- }
28
-
29
- // иначе зацкливаемся
30
- event.preventDefault();
31
- var target = tabbable[event.shiftKey ? tabbable.length - 1 : 0];
32
- if (target) {
33
- target.focus();
34
- }
35
- };
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isVisible = exports.isTabble = exports.isFocusable = exports.focusSelector = exports.findTabbableDescendants = void 0;
7
- var tabbableNode = /input|select|textarea|button|object/;
8
- var focusSelector = exports.focusSelector = /*#__PURE__*/['input', 'select', 'textarea', 'a', 'button', 'object', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'].join(',');
9
- var isHidden = function isHidden(el) {
10
- return el.offsetWidth <= 0 && el.offsetHeight <= 0 || el.style.display === 'none' || el.style.visibility === 'hidden' || el.style.opacity === '0';
11
- };
12
- var isVisible = exports.isVisible = function isVisible(element, parentContainer) {
13
- var parentElement = element;
14
- while (parentElement) {
15
- if (parentElement === parentContainer || parentElement === document.body) {
16
- break;
17
- }
18
- if (isHidden(parentElement)) {
19
- return false;
20
- }
21
- parentElement = parentElement.parentNode;
22
- }
23
- return true;
24
- };
25
- var getElementTabIndex = function getElementTabIndex(element) {
26
- var tabIndex = element.getAttribute('tabindex');
27
- return tabIndex === null ? NaN : parseInt(tabIndex, 10);
28
- };
29
- var isFocusable = exports.isFocusable = function isFocusable(element, parentContainer) {
30
- var nodeName = element.nodeName.toLowerCase();
31
- var isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
32
- var res = tabbableNode.test(nodeName) && !element.disabled || (element instanceof HTMLAnchorElement ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);
33
- return Boolean(res) && isVisible(element, parentContainer);
34
- };
35
- var isTabble = exports.isTabble = function isTabble(element, parentContainer) {
36
- var tabIndex = getElementTabIndex(element);
37
- var isTabIndexNaN = Number.isNaN(tabIndex);
38
- return (isTabIndexNaN || tabIndex >= 0) && isFocusable(element, parentContainer);
39
- };
40
-
41
- // Все элементы внутри данной ноды, до которых можно добраться табом
42
- var findTabbableDescendants = exports.findTabbableDescendants = function findTabbableDescendants(element) {
43
- return Array.from(element.querySelectorAll(focusSelector)).filter(function (el) {
44
- return isTabble(el, element);
45
- });
46
- };
@@ -1,95 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useFocusTrap = void 0;
7
- var _react = /*#__PURE__*/require("react");
8
- var _focusManager = /*#__PURE__*/require("../utils/focusManager");
9
- var _tabbable = /*#__PURE__*/require("../utils/tabbable");
10
- var _scopeTab = /*#__PURE__*/require("../utils/scopeTab");
11
- // Находим элемент для фокуса
12
- var getFocusElement = function getFocusElement(node, firstFocusSelector) {
13
- var focusElement = null;
14
- if (firstFocusSelector) {
15
- if (typeof firstFocusSelector === 'string') {
16
- focusElement = node.querySelector(firstFocusSelector);
17
- } else if (firstFocusSelector.current) {
18
- focusElement = firstFocusSelector.current;
19
- }
20
- }
21
- if (!focusElement) {
22
- var children = Array.from(node.querySelectorAll(_tabbable.focusSelector));
23
- focusElement = children.find(function (el) {
24
- return (0, _tabbable.isTabble)(el);
25
- }) || null;
26
- }
27
-
28
- // Если ничего не нашлось, то может ли сама нода быть под фокусом
29
- if (!focusElement && (0, _tabbable.isFocusable)(node)) {
30
- focusElement = node;
31
- }
32
- return focusElement;
33
- };
34
- var processNode = function processNode(node, firstFocusSelector, ref) {
35
- if (ref !== null && ref !== void 0 && ref.current) {
36
- ref.current.removeEventListener('animationend', function () {
37
- processNode(node, firstFocusSelector, ref);
38
- });
39
- }
40
- var focusElement = getFocusElement(node, firstFocusSelector);
41
- if (focusElement) {
42
- focusElement.focus();
43
- }
44
- };
45
- var focusManager = /*#__PURE__*/new _focusManager.FocusManager();
46
-
47
- /**
48
- * Захватывает фокус внутри DOM node.
49
- * */
50
- var useFocusTrap = exports.useFocusTrap = function useFocusTrap() {
51
- var active = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
52
- var firstFocusSelector = arguments.length > 1 ? arguments[1] : undefined;
53
- var focusAfterNode = arguments.length > 2 ? arguments[2] : undefined;
54
- var activeAfterAnimation = arguments.length > 3 ? arguments[3] : undefined;
55
- var ref = (0, _react.useRef)();
56
- var setRef = (0, _react.useCallback)(function (node) {
57
- if (ref.current) {
58
- focusManager.teardownScopedFocus();
59
- focusManager.returnFocus();
60
- }
61
- if (active && node) {
62
- focusManager.setupScopedFocus(node);
63
- focusManager.markForFocusAfter(focusAfterNode);
64
-
65
- // Delay processing the HTML node by a frame. This ensures focus is assigned correctly.
66
- setTimeout(function () {
67
- if (ref !== null && ref !== void 0 && ref.current && node.ownerDocument && activeAfterAnimation) {
68
- ref.current.addEventListener('animationend', function () {
69
- processNode(node, firstFocusSelector, ref);
70
- });
71
- } else if (node.ownerDocument) {
72
- processNode(node, firstFocusSelector);
73
- }
74
- });
75
- ref.current = node;
76
- return;
77
- }
78
- ref.current = null;
79
- }, [active, firstFocusSelector]);
80
- (0, _react.useEffect)(function () {
81
- if (!active) {
82
- return;
83
- }
84
- var handleKeyDown = function handleKeyDown(event) {
85
- if (event.key === 'Tab' && ref.current) {
86
- (0, _scopeTab.scopeTab)(ref.current, event);
87
- }
88
- };
89
- document.addEventListener('keydown', handleKeyDown);
90
- return function () {
91
- document.removeEventListener('keydown', handleKeyDown);
92
- };
93
- }, [active]);
94
- return setRef;
95
- };
@@ -1,90 +0,0 @@
1
- import { useCallback, useEffect, useRef } from 'react';
2
- import { FocusManager } from '../utils/focusManager';
3
- import { focusSelector, isFocusable, isTabble } from '../utils/tabbable';
4
- import { scopeTab } from '../utils/scopeTab';
5
-
6
- // Находим элемент для фокуса
7
- var getFocusElement = function getFocusElement(node, firstFocusSelector) {
8
- var focusElement = null;
9
- if (firstFocusSelector) {
10
- if (typeof firstFocusSelector === 'string') {
11
- focusElement = node.querySelector(firstFocusSelector);
12
- } else if (firstFocusSelector.current) {
13
- focusElement = firstFocusSelector.current;
14
- }
15
- }
16
- if (!focusElement) {
17
- var children = Array.from(node.querySelectorAll(focusSelector));
18
- focusElement = children.find(function (el) {
19
- return isTabble(el);
20
- }) || null;
21
- }
22
-
23
- // Если ничего не нашлось, то может ли сама нода быть под фокусом
24
- if (!focusElement && isFocusable(node)) {
25
- focusElement = node;
26
- }
27
- return focusElement;
28
- };
29
- var processNode = function processNode(node, firstFocusSelector, ref) {
30
- if (ref !== null && ref !== void 0 && ref.current) {
31
- ref.current.removeEventListener('animationend', function () {
32
- processNode(node, firstFocusSelector, ref);
33
- });
34
- }
35
- var focusElement = getFocusElement(node, firstFocusSelector);
36
- if (focusElement) {
37
- focusElement.focus();
38
- }
39
- };
40
- var focusManager = /*#__PURE__*/new FocusManager();
41
-
42
- /**
43
- * Захватывает фокус внутри DOM node.
44
- * */
45
- export var useFocusTrap = function useFocusTrap() {
46
- var active = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
47
- var firstFocusSelector = arguments.length > 1 ? arguments[1] : undefined;
48
- var focusAfterNode = arguments.length > 2 ? arguments[2] : undefined;
49
- var activeAfterAnimation = arguments.length > 3 ? arguments[3] : undefined;
50
- var ref = useRef();
51
- var setRef = useCallback(function (node) {
52
- if (ref.current) {
53
- focusManager.teardownScopedFocus();
54
- focusManager.returnFocus();
55
- }
56
- if (active && node) {
57
- focusManager.setupScopedFocus(node);
58
- focusManager.markForFocusAfter(focusAfterNode);
59
-
60
- // Delay processing the HTML node by a frame. This ensures focus is assigned correctly.
61
- setTimeout(function () {
62
- if (ref !== null && ref !== void 0 && ref.current && node.ownerDocument && activeAfterAnimation) {
63
- ref.current.addEventListener('animationend', function () {
64
- processNode(node, firstFocusSelector, ref);
65
- });
66
- } else if (node.ownerDocument) {
67
- processNode(node, firstFocusSelector);
68
- }
69
- });
70
- ref.current = node;
71
- return;
72
- }
73
- ref.current = null;
74
- }, [active, firstFocusSelector]);
75
- useEffect(function () {
76
- if (!active) {
77
- return;
78
- }
79
- var handleKeyDown = function handleKeyDown(event) {
80
- if (event.key === 'Tab' && ref.current) {
81
- scopeTab(ref.current, event);
82
- }
83
- };
84
- document.addEventListener('keydown', handleKeyDown);
85
- return function () {
86
- document.removeEventListener('keydown', handleKeyDown);
87
- };
88
- }, [active]);
89
- return setRef;
90
- };
@@ -1,55 +0,0 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
3
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
7
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
- import { findTabbableDescendants } from './tabbable';
9
-
10
- /**
11
- * Менеджер фокуса при открытии и закрытии нод при использовании focus-trap.
12
- * Также необходим, чтобы фокус всегда должен находиться внутри необходимой ноды.
13
- * */
14
- export var FocusManager = /*#__PURE__*/_createClass(function FocusManager() {
15
- var _this = this;
16
- _classCallCheck(this, FocusManager);
17
- // массив с элементами, которые нужно зафокусить после анмаунта
18
- _defineProperty(this, "focusAfterElements", []);
19
- // массив с trap нодами
20
- _defineProperty(this, "focusNodes", []);
21
- _defineProperty(this, "handleFocus", function () {
22
- // Фокус всегда должен находиться внутри необходимой ноды
23
- var focusNode = _this.focusNodes[_this.focusNodes.length - 1];
24
- if (!focusNode || focusNode.contains(document.activeElement)) {
25
- return;
26
- }
27
-
28
- // Выделяем первый tabbable элемент
29
- var el = findTabbableDescendants(focusNode)[0] || focusNode;
30
- el.focus();
31
- });
32
- // добавление на фокус после анмаунта
33
- _defineProperty(this, "markForFocusAfter", function (focusAfterNode) {
34
- var node = focusAfterNode && focusAfterNode.current ? focusAfterNode.current : document.activeElement;
35
- _this.focusAfterElements.push(node);
36
- });
37
- // фокус на необходимый элемент
38
- _defineProperty(this, "returnFocus", function () {
39
- var _this$focusAfterEleme;
40
- var toFocus = (_this$focusAfterEleme = _this.focusAfterElements.pop()) !== null && _this$focusAfterEleme !== void 0 ? _this$focusAfterEleme : null;
41
- if (toFocus) {
42
- toFocus.focus();
43
- }
44
- });
45
- // при маунте ноды
46
- _defineProperty(this, "setupScopedFocus", function (element) {
47
- _this.focusNodes.push(element);
48
- document.addEventListener('focusin', _this.handleFocus, true);
49
- });
50
- // при анмаунте
51
- _defineProperty(this, "teardownScopedFocus", function () {
52
- _this.focusNodes.pop();
53
- document.removeEventListener('focusin', _this.handleFocus);
54
- });
55
- });
@@ -1,30 +0,0 @@
1
- import { findTabbableDescendants } from './tabbable';
2
-
3
- /**
4
- * Управлление фокусом лишь внутри ноды через tab
5
- * @param node
6
- * @param event
7
- */
8
- export var scopeTab = function scopeTab(node, event) {
9
- var tabbable = findTabbableDescendants(node);
10
- if (!tabbable.length) {
11
- event.preventDefault();
12
- return;
13
- }
14
-
15
- // смотрим, является ли элемент крайним - первый или последним
16
- var finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
17
- var leavingFinalTabbable = finalTabbable === document.activeElement || node === document.activeElement;
18
-
19
- // если не является, то передаем обработку таба самому браузеру
20
- if (!leavingFinalTabbable) {
21
- return;
22
- }
23
-
24
- // иначе зацкливаемся
25
- event.preventDefault();
26
- var target = tabbable[event.shiftKey ? tabbable.length - 1 : 0];
27
- if (target) {
28
- target.focus();
29
- }
30
- };
@@ -1,40 +0,0 @@
1
- var tabbableNode = /input|select|textarea|button|object/;
2
- export var focusSelector = /*#__PURE__*/['input', 'select', 'textarea', 'a', 'button', 'object', '[tabindex]', 'audio[controls]', 'video[controls]', '[contenteditable]:not([contenteditable="false"])'].join(',');
3
- var isHidden = function isHidden(el) {
4
- return el.offsetWidth <= 0 && el.offsetHeight <= 0 || el.style.display === 'none' || el.style.visibility === 'hidden' || el.style.opacity === '0';
5
- };
6
- export var isVisible = function isVisible(element, parentContainer) {
7
- var parentElement = element;
8
- while (parentElement) {
9
- if (parentElement === parentContainer || parentElement === document.body) {
10
- break;
11
- }
12
- if (isHidden(parentElement)) {
13
- return false;
14
- }
15
- parentElement = parentElement.parentNode;
16
- }
17
- return true;
18
- };
19
- var getElementTabIndex = function getElementTabIndex(element) {
20
- var tabIndex = element.getAttribute('tabindex');
21
- return tabIndex === null ? NaN : parseInt(tabIndex, 10);
22
- };
23
- export var isFocusable = function isFocusable(element, parentContainer) {
24
- var nodeName = element.nodeName.toLowerCase();
25
- var isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
26
- var res = tabbableNode.test(nodeName) && !element.disabled || (element instanceof HTMLAnchorElement ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);
27
- return Boolean(res) && isVisible(element, parentContainer);
28
- };
29
- export var isTabble = function isTabble(element, parentContainer) {
30
- var tabIndex = getElementTabIndex(element);
31
- var isTabIndexNaN = Number.isNaN(tabIndex);
32
- return (isTabIndexNaN || tabIndex >= 0) && isFocusable(element, parentContainer);
33
- };
34
-
35
- // Все элементы внутри данной ноды, до которых можно добраться табом
36
- export var findTabbableDescendants = function findTabbableDescendants(element) {
37
- return Array.from(element.querySelectorAll(focusSelector)).filter(function (el) {
38
- return isTabble(el, element);
39
- });
40
- };