@opentripplanner/map-popup 3.1.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +20 -14
- package/esm/index.js.map +1 -1
- package/esm/styled.js +0 -21
- package/esm/styled.js.map +1 -1
- package/lib/index.d.ts +2 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -20
- package/lib/index.js.map +1 -1
- package/lib/styled.d.ts +0 -8
- package/lib/styled.d.ts.map +1 -1
- package/lib/styled.js +1 -33
- package/lib/styled.js.map +1 -1
- package/package.json +3 -1
- package/src/MapPopup.story.tsx +1 -11
- package/src/__snapshots__/MapPopup.story.tsx.snap +177 -222
- package/src/index.tsx +26 -20
- package/src/styled.ts +0 -29
- package/tsconfig.tsbuildinfo +1 -1
- package/esm/FocusTrapWrapper.js +0 -99
- package/esm/FocusTrapWrapper.js.map +0 -1
- package/lib/FocusTrapWrapper.d.ts +0 -26
- package/lib/FocusTrapWrapper.d.ts.map +0 -1
- package/lib/FocusTrapWrapper.js +0 -116
- package/lib/FocusTrapWrapper.js.map +0 -1
- package/src/FocusTrapWrapper.tsx +0 -95
package/lib/FocusTrapWrapper.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getNextSibling = getNextSibling;
|
|
7
|
-
exports.getPreviousSibling = getPreviousSibling;
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
|
|
12
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
-
|
|
14
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
-
|
|
16
|
-
function getEntries(query) {
|
|
17
|
-
const entries = Array.from(document.querySelectorAll(query));
|
|
18
|
-
const firstElement = entries[0];
|
|
19
|
-
const lastElement = entries[entries.length - 1];
|
|
20
|
-
return {
|
|
21
|
-
entries,
|
|
22
|
-
firstElement,
|
|
23
|
-
lastElement
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Helper method to find the next focusable sibling element relative to the
|
|
28
|
-
* specified element.
|
|
29
|
-
*
|
|
30
|
-
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
31
|
-
* @param {HTMLElement} element - Specified element (e.target)
|
|
32
|
-
* @returns {HTMLElement} - element to be focused
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
function getNextSibling(query, element) {
|
|
37
|
-
const {
|
|
38
|
-
entries,
|
|
39
|
-
firstElement,
|
|
40
|
-
lastElement
|
|
41
|
-
} = getEntries(query);
|
|
42
|
-
|
|
43
|
-
if (element === lastElement) {
|
|
44
|
-
return firstElement;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const elementIndex = entries.indexOf(element);
|
|
48
|
-
return entries[elementIndex + 1];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Helper method to find the previous focusable sibling element relative to the
|
|
52
|
-
* specified element.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
55
|
-
* @param {HTMLElement} element - Specified element (e.target)
|
|
56
|
-
* @returns {HTMLElement} - element to be focused
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function getPreviousSibling(query, element) {
|
|
61
|
-
const {
|
|
62
|
-
entries,
|
|
63
|
-
firstElement,
|
|
64
|
-
lastElement
|
|
65
|
-
} = getEntries(query);
|
|
66
|
-
|
|
67
|
-
if (element === firstElement) {
|
|
68
|
-
return lastElement;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const elementIndex = entries.indexOf(element);
|
|
72
|
-
return entries[elementIndex - 1];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const FocusTrapWrapper = ({
|
|
76
|
-
children,
|
|
77
|
-
closePopup = null,
|
|
78
|
-
id
|
|
79
|
-
}) => {
|
|
80
|
-
const queryId = `#${id}-popup-focus-trap button`;
|
|
81
|
-
const handleKeyDown = (0, _react.useCallback)(e => {
|
|
82
|
-
const element = e.target;
|
|
83
|
-
|
|
84
|
-
switch (e.key) {
|
|
85
|
-
case "Escape":
|
|
86
|
-
closePopup();
|
|
87
|
-
break;
|
|
88
|
-
|
|
89
|
-
case "Tab":
|
|
90
|
-
e.preventDefault();
|
|
91
|
-
|
|
92
|
-
if (e.shiftKey) {
|
|
93
|
-
var _getPreviousSibling;
|
|
94
|
-
|
|
95
|
-
(_getPreviousSibling = getPreviousSibling(queryId, element)) === null || _getPreviousSibling === void 0 ? void 0 : _getPreviousSibling.focus();
|
|
96
|
-
} else {
|
|
97
|
-
var _getNextSibling;
|
|
98
|
-
|
|
99
|
-
(_getNextSibling = getNextSibling(queryId, element)) === null || _getNextSibling === void 0 ? void 0 : _getNextSibling.focus();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
}
|
|
106
|
-
}, [closePopup]);
|
|
107
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
108
|
-
id: `${id}-popup-focus-trap`,
|
|
109
|
-
onKeyDown: handleKeyDown,
|
|
110
|
-
role: "presentation"
|
|
111
|
-
}, children);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
var _default = FocusTrapWrapper;
|
|
115
|
-
exports.default = _default;
|
|
116
|
-
//# sourceMappingURL=FocusTrapWrapper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/FocusTrapWrapper.tsx"],"names":["getEntries","query","entries","Array","from","document","querySelectorAll","firstElement","lastElement","length","getNextSibling","element","elementIndex","indexOf","getPreviousSibling","FocusTrapWrapper","children","closePopup","id","queryId","handleKeyDown","e","target","key","preventDefault","shiftKey","focus"],"mappings":";;;;;;;;;AAAA;;;;;;AAEA,SAASA,UAAT,CAAoBC,KAApB,EAAmC;AACjC,QAAMC,OAAO,GAAGC,KAAK,CAACC,IAAN,CAAWC,QAAQ,CAACC,gBAAT,CAA0BL,KAA1B,CAAX,CAAhB;AACA,QAAMM,YAAY,GAAGL,OAAO,CAAC,CAAD,CAA5B;AACA,QAAMM,WAAW,GAAGN,OAAO,CAACA,OAAO,CAACO,MAAR,GAAiB,CAAlB,CAA3B;AAEA,SAAO;AAAEP,IAAAA,OAAF;AAAWK,IAAAA,YAAX;AAAyBC,IAAAA;AAAzB,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,cAAT,CACLT,KADK,EAELU,OAFK,EAGQ;AACb,QAAM;AAAET,IAAAA,OAAF;AAAWK,IAAAA,YAAX;AAAyBC,IAAAA;AAAzB,MAAyCR,UAAU,CAACC,KAAD,CAAzD;;AAEA,MAAIU,OAAO,KAAKH,WAAhB,EAA6B;AAC3B,WAAOD,YAAP;AACD;;AACD,QAAMK,YAAY,GAAGV,OAAO,CAACW,OAAR,CAAg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P,KAKGJ,QALH,CADF;AASD,CAxCD;;eA0CeD,gB","sourcesContent":["import React, { ReactNode, useCallback } from \"react\";\n\nfunction getEntries(query: string) {\n const entries = Array.from(document.querySelectorAll(query));\n const firstElement = entries[0];\n const lastElement = entries[entries.length - 1];\n\n return { entries, firstElement, lastElement };\n}\n\n/**\n * Helper method to find the next focusable sibling element relative to the\n * specified element.\n *\n * @param {string} query - Argument that gets passed to document.querySelectorAll\n * @param {HTMLElement} element - Specified element (e.target)\n * @returns {HTMLElement} - element to be focused\n */\nexport function getNextSibling(\n query: string,\n element: EventTarget\n): HTMLElement {\n const { entries, firstElement, lastElement } = getEntries(query);\n\n if (element === lastElement) {\n return firstElement as HTMLElement;\n }\n const elementIndex = entries.indexOf(element as HTMLElement);\n return entries[elementIndex + 1] as HTMLElement;\n}\n\n/**\n * Helper method to find the previous focusable sibling element relative to the\n * specified element.\n *\n * @param {string} query - Argument that gets passed to document.querySelectorAll\n * @param {HTMLElement} element - Specified element (e.target)\n * @returns {HTMLElement} - element to be focused\n */\nexport function getPreviousSibling(\n query: string,\n element: EventTarget\n): HTMLElement {\n const { entries, firstElement, lastElement } = getEntries(query);\n\n if (element === firstElement) {\n return lastElement as HTMLElement;\n }\n const elementIndex = entries.indexOf(element as HTMLButtonElement);\n return entries[elementIndex - 1] as HTMLElement;\n}\n\nconst FocusTrapWrapper = ({\n children,\n closePopup = null,\n id\n}: {\n children: ReactNode | ReactNode[];\n closePopup?: (arg?: boolean) => void;\n id: string;\n}): JSX.Element => {\n const queryId = `#${id}-popup-focus-trap button`;\n const handleKeyDown = useCallback(\n e => {\n const element = e.target as HTMLElement;\n switch (e.key) {\n case \"Escape\":\n closePopup();\n break;\n case \"Tab\":\n e.preventDefault();\n if (e.shiftKey) {\n getPreviousSibling(queryId, element)?.focus();\n } else {\n getNextSibling(queryId, element)?.focus();\n }\n break;\n default:\n }\n },\n [closePopup]\n );\n\n return (\n <div\n id={`${id}-popup-focus-trap`}\n onKeyDown={handleKeyDown}\n role=\"presentation\"\n >\n {children}\n </div>\n );\n};\n\nexport default FocusTrapWrapper;\n"],"file":"FocusTrapWrapper.js"}
|
package/src/FocusTrapWrapper.tsx
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode, useCallback } from "react";
|
|
2
|
-
|
|
3
|
-
function getEntries(query: string) {
|
|
4
|
-
const entries = Array.from(document.querySelectorAll(query));
|
|
5
|
-
const firstElement = entries[0];
|
|
6
|
-
const lastElement = entries[entries.length - 1];
|
|
7
|
-
|
|
8
|
-
return { entries, firstElement, lastElement };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Helper method to find the next focusable sibling element relative to the
|
|
13
|
-
* specified element.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
16
|
-
* @param {HTMLElement} element - Specified element (e.target)
|
|
17
|
-
* @returns {HTMLElement} - element to be focused
|
|
18
|
-
*/
|
|
19
|
-
export function getNextSibling(
|
|
20
|
-
query: string,
|
|
21
|
-
element: EventTarget
|
|
22
|
-
): HTMLElement {
|
|
23
|
-
const { entries, firstElement, lastElement } = getEntries(query);
|
|
24
|
-
|
|
25
|
-
if (element === lastElement) {
|
|
26
|
-
return firstElement as HTMLElement;
|
|
27
|
-
}
|
|
28
|
-
const elementIndex = entries.indexOf(element as HTMLElement);
|
|
29
|
-
return entries[elementIndex + 1] as HTMLElement;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Helper method to find the previous focusable sibling element relative to the
|
|
34
|
-
* specified element.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
37
|
-
* @param {HTMLElement} element - Specified element (e.target)
|
|
38
|
-
* @returns {HTMLElement} - element to be focused
|
|
39
|
-
*/
|
|
40
|
-
export function getPreviousSibling(
|
|
41
|
-
query: string,
|
|
42
|
-
element: EventTarget
|
|
43
|
-
): HTMLElement {
|
|
44
|
-
const { entries, firstElement, lastElement } = getEntries(query);
|
|
45
|
-
|
|
46
|
-
if (element === firstElement) {
|
|
47
|
-
return lastElement as HTMLElement;
|
|
48
|
-
}
|
|
49
|
-
const elementIndex = entries.indexOf(element as HTMLButtonElement);
|
|
50
|
-
return entries[elementIndex - 1] as HTMLElement;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const FocusTrapWrapper = ({
|
|
54
|
-
children,
|
|
55
|
-
closePopup = null,
|
|
56
|
-
id
|
|
57
|
-
}: {
|
|
58
|
-
children: ReactNode | ReactNode[];
|
|
59
|
-
closePopup?: (arg?: boolean) => void;
|
|
60
|
-
id: string;
|
|
61
|
-
}): JSX.Element => {
|
|
62
|
-
const queryId = `#${id}-popup-focus-trap button`;
|
|
63
|
-
const handleKeyDown = useCallback(
|
|
64
|
-
e => {
|
|
65
|
-
const element = e.target as HTMLElement;
|
|
66
|
-
switch (e.key) {
|
|
67
|
-
case "Escape":
|
|
68
|
-
closePopup();
|
|
69
|
-
break;
|
|
70
|
-
case "Tab":
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
if (e.shiftKey) {
|
|
73
|
-
getPreviousSibling(queryId, element)?.focus();
|
|
74
|
-
} else {
|
|
75
|
-
getNextSibling(queryId, element)?.focus();
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
default:
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
[closePopup]
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return (
|
|
85
|
-
<div
|
|
86
|
-
id={`${id}-popup-focus-trap`}
|
|
87
|
-
onKeyDown={handleKeyDown}
|
|
88
|
-
role="presentation"
|
|
89
|
-
>
|
|
90
|
-
{children}
|
|
91
|
-
</div>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export default FocusTrapWrapper;
|