@opentripplanner/building-blocks 3.0.2-alpha.1 → 3.1.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/README.md +0 -4
- package/esm/alert/Alert.js +2 -1
- package/esm/alert/Alert.js.map +1 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/lib/alert/Alert.d.ts +3 -4
- package/lib/alert/Alert.d.ts.map +1 -1
- package/lib/alert/Alert.js +72 -103
- package/lib/alert/Alert.js.map +1 -1
- package/lib/colors/blue.js +18 -14
- package/lib/colors/blue.js.map +1 -1
- package/lib/colors/grey.js +18 -14
- package/lib/colors/grey.js.map +1 -1
- package/lib/colors/red.js +18 -14
- package/lib/colors/red.js.map +1 -1
- package/lib/dropdown/index.d.ts.map +1 -1
- package/lib/dropdown/index.js +101 -87
- package/lib/dropdown/index.js.map +1 -1
- package/lib/dropdown/styled.js +19 -72
- package/lib/dropdown/styled.js.map +1 -1
- package/lib/focus-trap-wrapper/dom-query.js +36 -20
- package/lib/focus-trap-wrapper/dom-query.js.map +1 -1
- package/lib/focus-trap-wrapper/index.d.ts.map +1 -1
- package/lib/focus-trap-wrapper/index.js +50 -52
- package/lib/focus-trap-wrapper/index.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +47 -36
- package/lib/index.js.map +1 -1
- package/lib/stories/ColorPalette.d.ts +0 -1
- package/lib/stories/ColorPalette.d.ts.map +1 -1
- package/lib/stories/ColorPalette.js +26 -37
- package/lib/stories/ColorPalette.js.map +1 -1
- package/package.json +3 -3
- package/src/alert/Alert.tsx +11 -8
- package/src/index.ts +8 -1
- package/src/stories/__snapshots__/alerts.story.tsx.snap +88 -83
- package/src/stories/__snapshots__/dropdown.story.tsx.snap +1 -1
- package/src/stories/__snapshots__/focusTrapStory.story.tsx.snap +1 -1
- package/src/stories/__snapshots__/index.story.tsx.snap +1 -1
- package/src/stories/alerts.story.tsx +23 -14
- package/tsconfig.tsbuildinfo +1 -1
package/lib/dropdown/index.js
CHANGED
|
@@ -1,97 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
17
5
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const react_1 = __importStar(require("react"));
|
|
27
|
-
const dom_query_1 = require("../focus-trap-wrapper/dom-query");
|
|
28
|
-
const styled_1 = require("./styled");
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _domQuery = require("../focus-trap-wrapper/dom-query");
|
|
9
|
+
var _styled = require("./styled");
|
|
10
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
29
11
|
/**
|
|
30
12
|
* Renders a dropdown menu. By default, only a passed "text" is rendered. If clicked,
|
|
31
13
|
* a floating div is rendered below the "text" with list contents inside. Clicking anywhere
|
|
32
14
|
* outside the floating div will close the dropdown.
|
|
33
15
|
*/
|
|
34
|
-
const Dropdown = ({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
16
|
+
const Dropdown = ({
|
|
17
|
+
alignMenuLeft,
|
|
18
|
+
children,
|
|
19
|
+
className,
|
|
20
|
+
id,
|
|
21
|
+
label,
|
|
22
|
+
listLabel,
|
|
23
|
+
text,
|
|
24
|
+
buttonStyle
|
|
25
|
+
}) => {
|
|
26
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
27
|
+
const containerRef = (0, _react.useRef)(null);
|
|
28
|
+
const toggleOpen = (0, _react.useCallback)(() => setOpen(!open), [open, setOpen]);
|
|
29
|
+
|
|
30
|
+
// Argument for document.querySelectorAll to target focusable elements.
|
|
31
|
+
const queryId = `#${id} button, #${id}-label`;
|
|
32
|
+
const isList = Array.isArray(children) ? children.every(child => /*#__PURE__*/_react.default.isValidElement(child) && child.type === "li") : /*#__PURE__*/_react.default.isValidElement(children) && children.type === "li";
|
|
33
|
+
|
|
34
|
+
// Adding document event listeners allows us to close the dropdown
|
|
35
|
+
// when the user interacts with any part of the page that isn't the dropdown
|
|
36
|
+
(0, _react.useEffect)(() => {
|
|
37
|
+
const handleExternalAction = e => {
|
|
38
|
+
var _containerRef$current;
|
|
39
|
+
if (!(containerRef !== null && containerRef !== void 0 && (_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(e.target))) {
|
|
40
|
+
setOpen(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
document.addEventListener("mousedown", handleExternalAction);
|
|
44
|
+
document.addEventListener("focusin", handleExternalAction);
|
|
45
|
+
document.addEventListener("keydown", handleExternalAction);
|
|
46
|
+
return () => {
|
|
47
|
+
document.removeEventListener("mousedown", handleExternalAction);
|
|
48
|
+
document.removeEventListener("focusin", handleExternalAction);
|
|
49
|
+
document.removeEventListener("keydown", handleExternalAction);
|
|
50
|
+
};
|
|
51
|
+
}, [containerRef]);
|
|
52
|
+
const handleKeyDown = (0, _react.useCallback)(e => {
|
|
53
|
+
var _getPreviousSibling, _getNextSibling;
|
|
54
|
+
const element = e.target;
|
|
55
|
+
switch (e.key) {
|
|
56
|
+
case "ArrowUp":
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
(_getPreviousSibling = (0, _domQuery.getPreviousSibling)(queryId, element)) === null || _getPreviousSibling === void 0 || _getPreviousSibling.focus();
|
|
59
|
+
break;
|
|
60
|
+
case "ArrowDown":
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
(_getNextSibling = (0, _domQuery.getNextSibling)(queryId, element)) === null || _getNextSibling === void 0 || _getNextSibling.focus();
|
|
63
|
+
break;
|
|
64
|
+
case "Escape":
|
|
65
|
+
setOpen(false);
|
|
66
|
+
break;
|
|
67
|
+
case " ":
|
|
68
|
+
case "Enter":
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
element.click();
|
|
71
|
+
if (element.id === `${id}-label` || element.id === `${id}-wrapper`) {
|
|
72
|
+
toggleOpen();
|
|
85
73
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
74
|
+
break;
|
|
75
|
+
default:
|
|
76
|
+
}
|
|
77
|
+
}, [id, toggleOpen]);
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement(_styled.DropdownWrapper, {
|
|
79
|
+
className: className,
|
|
80
|
+
id: `${id}-wrapper`,
|
|
81
|
+
onKeyDown: handleKeyDown,
|
|
82
|
+
ref: containerRef
|
|
83
|
+
}, /*#__PURE__*/_react.default.createElement(_styled.DropdownButton
|
|
84
|
+
// Only set aria-controls when the dropdown is open
|
|
85
|
+
// (otherwise, assistive technologies may not announce the dropdown correctly).
|
|
86
|
+
, {
|
|
87
|
+
"aria-controls": open ? id : undefined,
|
|
88
|
+
"aria-expanded": open,
|
|
89
|
+
"aria-haspopup": "listbox",
|
|
90
|
+
"aria-label": label,
|
|
91
|
+
id: `${id}-label`,
|
|
92
|
+
onClick: toggleOpen,
|
|
93
|
+
style: buttonStyle,
|
|
94
|
+
title: label,
|
|
95
|
+
type: "button"
|
|
96
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, text), /*#__PURE__*/_react.default.createElement("span", {
|
|
97
|
+
className: "caret",
|
|
98
|
+
role: "presentation"
|
|
99
|
+
})), open && /*#__PURE__*/_react.default.createElement(_styled.DropdownMenu, {
|
|
100
|
+
as: isList && "ul",
|
|
101
|
+
"aria-label": listLabel,
|
|
102
|
+
"aria-labelledby": listLabel ? undefined : `${id}-label`,
|
|
103
|
+
id: id,
|
|
104
|
+
onClick: toggleOpen,
|
|
105
|
+
alignLeft: alignMenuLeft,
|
|
106
|
+
role: isList && "listbox",
|
|
107
|
+
tabIndex: -1
|
|
108
|
+
}, children));
|
|
95
109
|
};
|
|
96
|
-
exports.default = Dropdown;
|
|
110
|
+
var _default = exports.default = Dropdown;
|
|
97
111
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","_interopRequireWildcard","require","_domQuery","_styled","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","Dropdown","alignMenuLeft","children","className","id","label","listLabel","text","buttonStyle","open","setOpen","useState","containerRef","useRef","toggleOpen","useCallback","queryId","isList","Array","isArray","every","child","React","isValidElement","type","useEffect","handleExternalAction","_containerRef$current","current","contains","target","document","addEventListener","removeEventListener","handleKeyDown","_getPreviousSibling","_getNextSibling","element","key","preventDefault","getPreviousSibling","focus","getNextSibling","click","createElement","DropdownWrapper","onKeyDown","ref","DropdownButton","undefined","onClick","style","title","role","DropdownMenu","as","alignLeft","tabIndex","_default","exports"],"sources":["../../src/dropdown/index.tsx"],"sourcesContent":["import React, {\n HTMLAttributes,\n KeyboardEvent,\n useCallback,\n useEffect,\n useRef,\n useState\n} from \"react\";\n\nimport {\n getNextSibling,\n getPreviousSibling\n} from \"../focus-trap-wrapper/dom-query\";\nimport { DropdownButton, DropdownMenu, DropdownWrapper } from \"./styled\";\n\nexport interface Props extends HTMLAttributes<HTMLElement> {\n alignMenuLeft?: boolean;\n buttonStyle?: React.CSSProperties;\n label?: string;\n listLabel?: string;\n text?: JSX.Element | string;\n nav?: boolean;\n}\n\n/**\n * Renders a dropdown menu. By default, only a passed \"text\" is rendered. If clicked,\n * a floating div is rendered below the \"text\" with list contents inside. Clicking anywhere\n * outside the floating div will close the dropdown.\n */\nconst Dropdown = ({\n alignMenuLeft,\n children,\n className,\n id,\n label,\n listLabel,\n text,\n buttonStyle\n}: Props): JSX.Element => {\n const [open, setOpen] = useState(false);\n\n const containerRef = useRef<HTMLSpanElement>(null);\n\n const toggleOpen = useCallback(() => setOpen(!open), [open, setOpen]);\n\n // Argument for document.querySelectorAll to target focusable elements.\n const queryId = `#${id} button, #${id}-label`;\n\n const isList = Array.isArray(children)\n ? children.every(\n child => React.isValidElement(child) && child.type === \"li\"\n )\n : React.isValidElement(children) && children.type === \"li\";\n\n // Adding document event listeners allows us to close the dropdown\n // when the user interacts with any part of the page that isn't the dropdown\n useEffect(() => {\n const handleExternalAction = (e: Event): void => {\n if (!containerRef?.current?.contains(e.target as HTMLElement)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", handleExternalAction);\n document.addEventListener(\"focusin\", handleExternalAction);\n document.addEventListener(\"keydown\", handleExternalAction);\n return () => {\n document.removeEventListener(\"mousedown\", handleExternalAction);\n document.removeEventListener(\"focusin\", handleExternalAction);\n document.removeEventListener(\"keydown\", handleExternalAction);\n };\n }, [containerRef]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent): void => {\n const element = e.target as HTMLElement;\n switch (e.key) {\n case \"ArrowUp\":\n e.preventDefault();\n getPreviousSibling(queryId, element)?.focus();\n break;\n case \"ArrowDown\":\n e.preventDefault();\n getNextSibling(queryId, element)?.focus();\n break;\n case \"Escape\":\n setOpen(false);\n break;\n case \" \":\n case \"Enter\":\n e.preventDefault();\n element.click();\n if (element.id === `${id}-label` || element.id === `${id}-wrapper`) {\n toggleOpen();\n }\n break;\n default:\n }\n },\n [id, toggleOpen]\n );\n\n return (\n <DropdownWrapper\n className={className}\n id={`${id}-wrapper`}\n onKeyDown={handleKeyDown}\n ref={containerRef}\n >\n <DropdownButton\n // Only set aria-controls when the dropdown is open\n // (otherwise, assistive technologies may not announce the dropdown correctly).\n aria-controls={open ? id : undefined}\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-label={label}\n id={`${id}-label`}\n onClick={toggleOpen}\n style={buttonStyle}\n title={label}\n type=\"button\"\n >\n <span>{text}</span>\n <span className=\"caret\" role=\"presentation\" />\n </DropdownButton>\n {open && (\n <DropdownMenu\n as={isList && \"ul\"}\n aria-label={listLabel}\n aria-labelledby={listLabel ? undefined : `${id}-label`}\n id={id}\n onClick={toggleOpen}\n alignLeft={alignMenuLeft}\n role={isList && \"listbox\"}\n tabIndex={-1}\n >\n {children}\n </DropdownMenu>\n )}\n </DropdownWrapper>\n );\n};\n\nexport default Dropdown;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AASA,IAAAC,SAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AAAyE,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,CAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,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I,EAAEpC,MAAM,IAAI,SAAU;IAC1BwC,QAAQ,EAAE,CAAC;EAAE,GAEZvD,QACW,CAED,CAAC;AAEtB,CAAC;AAAC,IAAAwD,QAAA,GAAAC,OAAA,CAAApE,OAAA,GAEaS,QAAQ","ignoreList":[]}
|
package/lib/dropdown/styled.js
CHANGED
|
@@ -1,75 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DropdownWrapper = exports.DropdownMenu = exports.DropdownButton = void 0;
|
|
7
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
-
const grey_1 = __importDefault(require("../colors/grey"));
|
|
9
|
-
exports.DropdownButton = styled_components_1.default.button `
|
|
10
|
-
background: #fff;
|
|
11
|
-
border: 1px solid black;
|
|
12
|
-
border-radius: 5px;
|
|
13
|
-
color: inherit;
|
|
14
|
-
padding: 5px 7px;
|
|
15
|
-
transition: all 0.1s ease-in-out;
|
|
16
|
-
|
|
17
|
-
span.caret {
|
|
18
|
-
border-left: 4px solid transparent;
|
|
19
|
-
border-right: 4px solid transparent;
|
|
20
|
-
border-top: 4px solid;
|
|
21
|
-
color: inherit;
|
|
22
|
-
display: inline-block;
|
|
23
|
-
height: 0;
|
|
24
|
-
margin-left: 5px;
|
|
25
|
-
vertical-align: middle;
|
|
26
|
-
width: 0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
&:hover,
|
|
30
|
-
&[aria-expanded="true"] {
|
|
31
|
-
background: ${grey_1.default[50]};
|
|
32
|
-
color: black;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
exports.DropdownMenu = styled_components_1.default.div `
|
|
37
|
-
background-clip: padding-box;
|
|
38
|
-
background-color: #fff;
|
|
39
|
-
border-radius: 4px;
|
|
40
|
-
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
41
|
-
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
|
|
42
|
-
color: #333;
|
|
43
|
-
list-style: none;
|
|
44
|
-
margin: 2px 0 0;
|
|
45
|
-
min-width: 160px;
|
|
46
|
-
padding: 5px 0;
|
|
47
|
-
position: absolute;
|
|
48
|
-
${props => (props.alignLeft ? "left: 0;" : "right: 0;")}
|
|
49
|
-
top: 100%;
|
|
50
|
-
width: 100%;
|
|
51
|
-
z-index: 1000;
|
|
52
2
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
float: ${props => (props.pullRight ? "right" : "left")};
|
|
73
|
-
position: relative;
|
|
74
|
-
`;
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.DropdownWrapper = exports.DropdownMenu = exports.DropdownButton = void 0;
|
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
|
+
var _grey = _interopRequireDefault(require("../colors/grey"));
|
|
10
|
+
const DropdownButton = exports.DropdownButton = _styledComponents.default.button.withConfig({
|
|
11
|
+
displayName: "styled__DropdownButton",
|
|
12
|
+
componentId: "sc-kes9ha-0"
|
|
13
|
+
})(["background:#fff;border:1px solid black;border-radius:5px;color:inherit;padding:5px 7px;transition:all 0.1s ease-in-out;span.caret{border-left:4px solid transparent;border-right:4px solid transparent;border-top:4px solid;color:inherit;display:inline-block;height:0;margin-left:5px;vertical-align:middle;width:0;}&:hover,&[aria-expanded=\"true\"]{background:", ";color:black;cursor:pointer;}"], _grey.default[50]);
|
|
14
|
+
const DropdownMenu = exports.DropdownMenu = _styledComponents.default.div.withConfig({
|
|
15
|
+
displayName: "styled__DropdownMenu",
|
|
16
|
+
componentId: "sc-kes9ha-1"
|
|
17
|
+
})(["background-clip:padding-box;background-color:#fff;border-radius:4px;border:1px solid rgba(0,0,0,0.15);box-shadow:0 6px 12px rgba(0,0,0,0.175);color:#333;list-style:none;margin:2px 0 0;min-width:160px;padding:5px 0;position:absolute;", " top:100%;width:100%;z-index:1000;hr{margin:0;padding:0;}a,button{background:transparent;border:none;cursor:pointer;padding:5px 15px;text-align:start;width:100%;&:hover{background:", ";}}"], props => props.alignLeft ? "left: 0;" : "right: 0;", _grey.default[50]);
|
|
18
|
+
const DropdownWrapper = exports.DropdownWrapper = _styledComponents.default.span.withConfig({
|
|
19
|
+
displayName: "styled__DropdownWrapper",
|
|
20
|
+
componentId: "sc-kes9ha-2"
|
|
21
|
+
})(["float:", ";position:relative;"], props => props.pullRight ? "right" : "left");
|
|
75
22
|
//# sourceMappingURL=styled.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.js","
|
|
1
|
+
{"version":3,"file":"styled.js","names":["_styledComponents","_interopRequireDefault","require","_grey","DropdownButton","exports","styled","button","withConfig","displayName","componentId","grey","DropdownMenu","div","props","alignLeft","DropdownWrapper","span","pullRight"],"sources":["../../src/dropdown/styled.tsx"],"sourcesContent":["import styled from \"styled-components\";\nimport grey from \"../colors/grey\";\n\nexport const DropdownButton = styled.button`\n background: #fff;\n border: 1px solid black;\n border-radius: 5px;\n color: inherit;\n padding: 5px 7px;\n transition: all 0.1s ease-in-out;\n\n span.caret {\n border-left: 4px solid transparent;\n border-right: 4px solid transparent;\n border-top: 4px solid;\n color: inherit;\n display: inline-block;\n height: 0;\n margin-left: 5px;\n vertical-align: middle;\n width: 0;\n }\n\n &:hover,\n &[aria-expanded=\"true\"] {\n background: ${grey[50]};\n color: black;\n cursor: pointer;\n }\n`;\n\nexport const DropdownMenu = styled.div<{ alignLeft?: boolean }>`\n background-clip: padding-box;\n background-color: #fff;\n border-radius: 4px;\n border: 1px solid rgba(0, 0, 0, 0.15);\n box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);\n color: #333;\n list-style: none;\n margin: 2px 0 0;\n min-width: 160px;\n padding: 5px 0;\n position: absolute;\n ${props => (props.alignLeft ? \"left: 0;\" : \"right: 0;\")}\n top: 100%;\n width: 100%;\n z-index: 1000;\n\n hr {\n margin: 0;\n padding: 0;\n }\n a,\n button {\n background: transparent;\n border: none;\n cursor: pointer;\n padding: 5px 15px;\n text-align: start;\n width: 100%;\n\n &:hover {\n background: ${grey[50]};\n }\n }\n`;\n\nexport const DropdownWrapper = styled.span<{ pullRight?: boolean }>`\n float: ${props => (props.pullRight ? \"right\" : \"left\")};\n position: relative;\n`;\n"],"mappings":";;;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAGE,yBAAM,CAACC,MAAM,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,8YAsBzBC,aAAI,CAAC,EAAE,CAAC,CAIzB;AAEM,MAAMC,YAAY,GAAAP,OAAA,CAAAO,YAAA,GAAGN,yBAAM,CAACO,GAAG,CAAAL,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,gbAYlCI,KAAK,IAAKA,KAAK,CAACC,SAAS,GAAG,UAAU,GAAG,WAAY,EAmBrCJ,aAAI,CAAC,EAAE,CAAC,CAG3B;AAEM,MAAMK,eAAe,GAAAX,OAAA,CAAAW,eAAA,GAAGV,yBAAM,CAACW,IAAI,CAAAT,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,sCAC/BI,KAAK,IAAKA,KAAK,CAACI,SAAS,GAAG,OAAO,GAAG,MAAO,CAEvD","ignoreList":[]}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getNextSibling = getNextSibling;
|
|
7
|
+
exports.getPreviousSibling = getPreviousSibling;
|
|
4
8
|
function getEntries(query) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const entries = Array.from(document.querySelectorAll(query));
|
|
10
|
+
const firstElement = entries[0];
|
|
11
|
+
const lastElement = entries[entries.length - 1];
|
|
12
|
+
return {
|
|
13
|
+
entries,
|
|
14
|
+
firstElement,
|
|
15
|
+
lastElement
|
|
16
|
+
};
|
|
9
17
|
}
|
|
18
|
+
|
|
10
19
|
/**
|
|
11
20
|
* Helper method to find the next focusable sibling element relative to the
|
|
12
21
|
* specified element.
|
|
@@ -16,14 +25,18 @@ function getEntries(query) {
|
|
|
16
25
|
* @returns {HTMLElement} - element to be focused
|
|
17
26
|
*/
|
|
18
27
|
function getNextSibling(query, element) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
const {
|
|
29
|
+
entries,
|
|
30
|
+
firstElement,
|
|
31
|
+
lastElement
|
|
32
|
+
} = getEntries(query);
|
|
33
|
+
if (element === lastElement) {
|
|
34
|
+
return firstElement;
|
|
35
|
+
}
|
|
36
|
+
const elementIndex = entries.indexOf(element);
|
|
37
|
+
return entries[elementIndex + 1];
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
|
|
27
40
|
/**
|
|
28
41
|
* Helper method to find the previous focusable sibling element relative to the
|
|
29
42
|
* specified element.
|
|
@@ -33,12 +46,15 @@ exports.getNextSibling = getNextSibling;
|
|
|
33
46
|
* @returns {HTMLElement} - element to be focused
|
|
34
47
|
*/
|
|
35
48
|
function getPreviousSibling(query, element) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
const {
|
|
50
|
+
entries,
|
|
51
|
+
firstElement,
|
|
52
|
+
lastElement
|
|
53
|
+
} = getEntries(query);
|
|
54
|
+
if (element === firstElement) {
|
|
55
|
+
return lastElement;
|
|
56
|
+
}
|
|
57
|
+
const elementIndex = entries.indexOf(element);
|
|
58
|
+
return entries[elementIndex - 1];
|
|
42
59
|
}
|
|
43
|
-
exports.getPreviousSibling = getPreviousSibling;
|
|
44
60
|
//# sourceMappingURL=dom-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-query.js","
|
|
1
|
+
{"version":3,"file":"dom-query.js","names":["getEntries","query","entries","Array","from","document","querySelectorAll","firstElement","lastElement","length","getNextSibling","element","elementIndex","indexOf","getPreviousSibling"],"sources":["../../src/focus-trap-wrapper/dom-query.ts"],"sourcesContent":["function 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"],"mappings":";;;;;;;AAAA,SAASA,UAAUA,CAACC,KAAa,EAAE;EACjC,MAAMC,OAAO,GAAGC,KAAK,CAACC,IAAI,CAACC,QAAQ,CAACC,gBAAgB,CAACL,KAAK,CAAC,CAAC;EAC5D,MAAMM,YAAY,GAAGL,OAAO,CAAC,CAAC,CAAC;EAC/B,MAAMM,WAAW,GAAGN,OAAO,CAACA,OAAO,CAACO,MAAM,GAAG,CAAC,CAAC;EAE/C,OAAO;IAAEP,OAAO;IAAEK,YAAY;IAAEC;EAAY,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAC5BT,KAAa,EACbU,OAAoB,EACP;EACb,MAAM;IAAET,OAAO;IAAEK,YAAY;IAAEC;EAAY,CAAC,GAAGR,UAAU,CAACC,KAAK,CAAC;EAEhE,IAAIU,OAAO,KAAKH,WAAW,EAAE;IAC3B,OAAOD,YAAY;EACrB;EACA,MAAMK,YAAY,GAAGV,OAAO,CAACW,OAAO,CAACF,OAAsB,CAAC;EAC5D,OAAOT,OAAO,CAACU,YAAY,GAAG,CAAC,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,kBAAkBA,CAChCb,KAAa,EACbU,OAAoB,EACP;EACb,MAAM;IAAET,OAAO;IAAEK,YAAY;IAAEC;EAAY,CAAC,GAAGR,UAAU,CAACC,KAAK,CAAC;EAEhE,IAAIU,OAAO,KAAKJ,YAAY,EAAE;IAC5B,OAAOC,WAAW;EACpB;EACA,MAAMI,YAAY,GAAGV,OAAO,CAACW,OAAO,CAACF,OAA4B,CAAC;EAClE,OAAOT,OAAO,CAACU,YAAY,GAAG,CAAC,CAAC;AAClC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/focus-trap-wrapper/index.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjE,QAAA,MAAM,gBAAgB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/focus-trap-wrapper/index.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAe,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjE,QAAA,MAAM,gBAAgB,GAAI,6CAKvB;IACD,QAAQ,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IAClC,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,KAAG,GAAG,CAAC,OA8BP,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;AAE9C,eAAe,gBAAgB,CAAC"}
|
|
@@ -1,57 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
17
5
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
Object.defineProperty(exports, "getNextSibling", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _domQuery.getNextSibling;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "getPreviousSibling", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _domQuery.getPreviousSibling;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
20
|
+
var _domQuery = require("./dom-query");
|
|
21
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
22
|
+
const FocusTrapWrapper = ({
|
|
23
|
+
children,
|
|
24
|
+
closePopup = null,
|
|
25
|
+
focusElements = ["button", "a", "input", "select"],
|
|
26
|
+
id
|
|
27
|
+
}) => {
|
|
28
|
+
const queryId = focusElements.map(el => `#${id}-focus-trap ${el}:not([disabled])`).join(", ");
|
|
29
|
+
const handleKeyDown = (0, _react.useCallback)(e => {
|
|
30
|
+
const element = e.target;
|
|
31
|
+
switch (e.key) {
|
|
32
|
+
case "Escape":
|
|
33
|
+
closePopup();
|
|
34
|
+
break;
|
|
35
|
+
case "Tab":
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
if (e.shiftKey) {
|
|
38
|
+
var _getPreviousSibling;
|
|
39
|
+
(_getPreviousSibling = (0, _domQuery.getPreviousSibling)(queryId, element)) === null || _getPreviousSibling === void 0 || _getPreviousSibling.focus();
|
|
40
|
+
} else {
|
|
41
|
+
var _getNextSibling;
|
|
42
|
+
(_getNextSibling = (0, _domQuery.getNextSibling)(queryId, element)) === null || _getNextSibling === void 0 || _getNextSibling.focus();
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
}
|
|
47
|
+
}, [closePopup]);
|
|
48
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
49
|
+
id: `${id}-focus-trap`,
|
|
50
|
+
onKeyDown: handleKeyDown,
|
|
51
|
+
role: "presentation"
|
|
52
|
+
}, children);
|
|
55
53
|
};
|
|
56
|
-
exports.default = FocusTrapWrapper;
|
|
54
|
+
var _default = exports.default = FocusTrapWrapper;
|
|
57
55
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","_interopRequireWildcard","require","_domQuery","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","FocusTrapWrapper","children","closePopup","focusElements","id","queryId","map","el","join","handleKeyDown","useCallback","element","target","key","preventDefault","shiftKey","_getPreviousSibling","getPreviousSibling","focus","_getNextSibling","getNextSibling","createElement","onKeyDown","role","_default","exports"],"sources":["../../src/focus-trap-wrapper/index.tsx"],"sourcesContent":["import React, { ReactNode, useCallback } from \"react\";\nimport { getNextSibling, getPreviousSibling } from \"./dom-query\";\n\nconst FocusTrapWrapper = ({\n children,\n closePopup = null,\n focusElements = [\"button\", \"a\", \"input\", \"select\"],\n id\n}: {\n children: ReactNode | ReactNode[];\n closePopup?: (arg?: boolean) => void;\n id: string;\n focusElements?: string[];\n}): JSX.Element => {\n const queryId = focusElements\n .map(el => `#${id}-focus-trap ${el}:not([disabled])`)\n .join(\", \");\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 id={`${id}-focus-trap`} onKeyDown={handleKeyDown} role=\"presentation\">\n {children}\n </div>\n );\n};\n\nexport { getNextSibling, getPreviousSibling };\n\nexport default FocusTrapWrapper;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAAiE,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA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CAAC;QAClB,IAAIjC,CAAC,CAACkC,QAAQ,EAAE;UAAA,IAAAC,mBAAA;UACd,CAAAA,mBAAA,OAAAC,4BAAkB,EAACZ,OAAO,EAAEM,OAAO,CAAC,cAAAK,mBAAA,eAApCA,mBAAA,CAAsCE,KAAK,CAAC,CAAC;QAC/C,CAAC,MAAM;UAAA,IAAAC,eAAA;UACL,CAAAA,eAAA,OAAAC,wBAAc,EAACf,OAAO,EAAEM,OAAO,CAAC,cAAAQ,eAAA,eAAhCA,eAAA,CAAkCD,KAAK,CAAC,CAAC;QAC3C;QACA;MACF;IACF;EACF,CAAC,EACD,CAAChB,UAAU,CACb,CAAC;EAED,oBACEzB,MAAA,CAAAc,OAAA,CAAA8B,aAAA;IAAKjB,EAAE,EAAE,GAAGA,EAAE,aAAc;IAACkB,SAAS,EAAEb,aAAc;IAACc,IAAI,EAAC;EAAc,GACvEtB,QACE,CAAC;AAEV,CAAC;AAAC,IAAAuB,QAAA,GAAAC,OAAA,CAAAlC,OAAA,GAIaS,gBAAgB","ignoreList":[]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Dropdown from "./dropdown";
|
|
2
2
|
import FocusTrapWrapper, { getNextSibling, getPreviousSibling } from "./focus-trap-wrapper";
|
|
3
|
-
|
|
3
|
+
import Alert from "./alert/Alert";
|
|
4
|
+
export { Alert, Dropdown, FocusTrapWrapper, getNextSibling, getPreviousSibling };
|
|
4
5
|
declare const _default: {
|
|
5
6
|
blue: {
|
|
6
7
|
50: string;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,gBAAgB,EAAE,EACvB,cAAc,EACd,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,gBAAgB,EAAE,EACvB,cAAc,EACd,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,MAAM,eAAe,CAAC;AAGlC,OAAO,EACL,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EACnB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACF,wBAAmC"}
|