@react-aria/live-announcer 3.0.1 → 3.0.4
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/dist/main.js +110 -143
- package/dist/main.js.map +1 -1
- package/dist/module.js +95 -122
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/main.js
CHANGED
|
@@ -1,163 +1,130 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var $9snhK$react = require("react");
|
|
2
|
+
var $9snhK$reactdom = require("react-dom");
|
|
3
|
+
var $9snhK$reactariavisuallyhidden = require("@react-aria/visually-hidden");
|
|
4
|
+
|
|
5
|
+
function $parcel$exportWildcard(dest, source) {
|
|
6
|
+
Object.keys(source).forEach(function(key) {
|
|
7
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
11
|
+
Object.defineProperty(dest, key, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function get() {
|
|
14
|
+
return source[key];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
16
18
|
|
|
19
|
+
return dest;
|
|
20
|
+
}
|
|
17
21
|
function $parcel$interopDefault(a) {
|
|
18
22
|
return a && a.__esModule ? a.default : a;
|
|
19
23
|
}
|
|
24
|
+
function $parcel$export(e, n, v, s) {
|
|
25
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
26
|
+
}
|
|
27
|
+
var $97cebfa4133ebec3$exports = {};
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let $daf77d092755557a1dfdc345b21308d$var$liveRegionAnnouncer = /*#__PURE__*/_react.createRef();
|
|
29
|
+
$parcel$export($97cebfa4133ebec3$exports, "announce", () => $97cebfa4133ebec3$export$a9b970dcc4ae71a9);
|
|
30
|
+
$parcel$export($97cebfa4133ebec3$exports, "clearAnnouncer", () => $97cebfa4133ebec3$export$d10ae4f68404609a);
|
|
31
|
+
$parcel$export($97cebfa4133ebec3$exports, "destroyAnnouncer", () => $97cebfa4133ebec3$export$d8686216b8b81b2f);
|
|
25
32
|
|
|
26
|
-
let $daf77d092755557a1dfdc345b21308d$var$node = null;
|
|
27
|
-
let $daf77d092755557a1dfdc345b21308d$var$messageId = 0;
|
|
28
|
-
/**
|
|
29
|
-
* Announces the message using screen reader technology.
|
|
30
|
-
*/
|
|
31
33
|
|
|
32
|
-
function announce(message, assertiveness, timeout) {
|
|
33
|
-
if (assertiveness === void 0) {
|
|
34
|
-
assertiveness = 'assertive';
|
|
35
|
-
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
36
|
+
let $97cebfa4133ebec3$var$liveRegionAnnouncer = /*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createRef();
|
|
37
|
+
let $97cebfa4133ebec3$var$node = null;
|
|
38
|
+
let $97cebfa4133ebec3$var$messageId = 0;
|
|
39
|
+
function $97cebfa4133ebec3$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
40
|
+
$97cebfa4133ebec3$var$ensureInstance((announcer)=>announcer.announce(message, assertiveness, timeout)
|
|
41
|
+
);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
exports.announce = announce;
|
|
49
|
-
|
|
50
|
-
function clearAnnouncer(assertiveness) {
|
|
51
|
-
$daf77d092755557a1dfdc345b21308d$var$ensureInstance(announcer => announcer.clear(assertiveness));
|
|
43
|
+
function $97cebfa4133ebec3$export$d10ae4f68404609a(assertiveness) {
|
|
44
|
+
$97cebfa4133ebec3$var$ensureInstance((announcer)=>announcer.clear(assertiveness)
|
|
45
|
+
);
|
|
52
46
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function destroyAnnouncer() {
|
|
61
|
-
if ($daf77d092755557a1dfdc345b21308d$var$liveRegionAnnouncer.current) {
|
|
62
|
-
_reactDom.unmountComponentAtNode($daf77d092755557a1dfdc345b21308d$var$node);
|
|
63
|
-
|
|
64
|
-
document.body.removeChild($daf77d092755557a1dfdc345b21308d$var$node);
|
|
65
|
-
$daf77d092755557a1dfdc345b21308d$var$node = null;
|
|
66
|
-
}
|
|
47
|
+
function $97cebfa4133ebec3$export$d8686216b8b81b2f() {
|
|
48
|
+
if ($97cebfa4133ebec3$var$liveRegionAnnouncer.current) {
|
|
49
|
+
($parcel$interopDefault($9snhK$reactdom)).unmountComponentAtNode($97cebfa4133ebec3$var$node);
|
|
50
|
+
document.body.removeChild($97cebfa4133ebec3$var$node);
|
|
51
|
+
$97cebfa4133ebec3$var$node = null;
|
|
52
|
+
}
|
|
67
53
|
}
|
|
68
54
|
/**
|
|
69
55
|
* Ensures we only have one instance of the announcer so that we don't have elements competing.
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
56
|
+
*/ function $97cebfa4133ebec3$var$ensureInstance(callback) {
|
|
57
|
+
if (!$97cebfa4133ebec3$var$liveRegionAnnouncer.current) {
|
|
58
|
+
$97cebfa4133ebec3$var$node = document.createElement('div');
|
|
59
|
+
$97cebfa4133ebec3$var$node.dataset.liveAnnouncer = 'true';
|
|
60
|
+
document.body.prepend($97cebfa4133ebec3$var$node);
|
|
61
|
+
($parcel$interopDefault($9snhK$reactdom)).render(/*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement($97cebfa4133ebec3$var$LiveRegionAnnouncer, {
|
|
62
|
+
ref: $97cebfa4133ebec3$var$liveRegionAnnouncer
|
|
63
|
+
}), $97cebfa4133ebec3$var$node, ()=>callback($97cebfa4133ebec3$var$liveRegionAnnouncer.current)
|
|
64
|
+
);
|
|
65
|
+
} else callback($97cebfa4133ebec3$var$liveRegionAnnouncer.current);
|
|
66
|
+
}
|
|
67
|
+
const $97cebfa4133ebec3$var$LiveRegionAnnouncer = /*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).forwardRef((_, ref)=>{
|
|
68
|
+
let [assertiveMessages, setAssertiveMessages] = $9snhK$react.useState([]);
|
|
69
|
+
let [politeMessages, setPoliteMessages] = $9snhK$react.useState([]);
|
|
70
|
+
let clear = (assertiveness)=>{
|
|
71
|
+
if (!assertiveness || assertiveness === 'assertive') setAssertiveMessages([]);
|
|
72
|
+
if (!assertiveness || assertiveness === 'polite') setPoliteMessages([]);
|
|
73
|
+
};
|
|
74
|
+
let $97cebfa4133ebec3$export$a9b970dcc4ae71a9 = (message1, assertiveness = 'assertive', timeout = $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY)=>{
|
|
75
|
+
let id = $97cebfa4133ebec3$var$messageId++;
|
|
76
|
+
if (assertiveness === 'assertive') setAssertiveMessages((messages)=>[
|
|
77
|
+
...messages,
|
|
78
|
+
{
|
|
79
|
+
id: id,
|
|
80
|
+
text: message1
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
);
|
|
84
|
+
else setPoliteMessages((messages)=>[
|
|
85
|
+
...messages,
|
|
86
|
+
{
|
|
87
|
+
id: id,
|
|
88
|
+
text: message1
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
);
|
|
92
|
+
if (message1 !== '') setTimeout(()=>{
|
|
93
|
+
if (assertiveness === 'assertive') setAssertiveMessages((messages)=>messages.filter((message)=>message.id !== id
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
else setPoliteMessages((messages)=>messages.filter((message)=>message.id !== id
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
}, timeout);
|
|
100
|
+
};
|
|
101
|
+
$9snhK$react.useImperativeHandle(ref, ()=>({
|
|
102
|
+
announce: $97cebfa4133ebec3$export$a9b970dcc4ae71a9,
|
|
103
|
+
clear: clear
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
return(/*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement($9snhK$react.Fragment, null, /*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement($97cebfa4133ebec3$var$MessageBlock, {
|
|
107
|
+
"aria-live": "assertive"
|
|
108
|
+
}, assertiveMessages.map((message)=>/*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement("div", {
|
|
109
|
+
key: message.id
|
|
110
|
+
}, message.text)
|
|
111
|
+
)), /*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement($97cebfa4133ebec3$var$MessageBlock, {
|
|
112
|
+
"aria-live": "polite"
|
|
113
|
+
}, politeMessages.map((message)=>/*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement("div", {
|
|
114
|
+
key: message.id
|
|
115
|
+
}, message.text)
|
|
116
|
+
))));
|
|
117
|
+
});
|
|
118
|
+
function $97cebfa4133ebec3$var$MessageBlock({ children: children , 'aria-live': ariaLive }) {
|
|
119
|
+
return(/*#__PURE__*/ ($parcel$interopDefault($9snhK$react)).createElement($9snhK$reactariavisuallyhidden.VisuallyHidden, {
|
|
120
|
+
role: "log",
|
|
121
|
+
"aria-live": ariaLive,
|
|
122
|
+
"aria-relevant": "additions"
|
|
123
|
+
}, children));
|
|
87
124
|
}
|
|
88
125
|
|
|
89
|
-
const $daf77d092755557a1dfdc345b21308d$var$LiveRegionAnnouncer = /*#__PURE__*/_react.forwardRef((_, ref) => {
|
|
90
|
-
let [assertiveMessages, setAssertiveMessages] = useState([]);
|
|
91
|
-
let [politeMessages, setPoliteMessages] = useState([]);
|
|
92
|
-
|
|
93
|
-
let clear = assertiveness => {
|
|
94
|
-
if (!assertiveness || assertiveness === 'assertive') {
|
|
95
|
-
setAssertiveMessages([]);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!assertiveness || assertiveness === 'polite') {
|
|
99
|
-
setPoliteMessages([]);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
let announce = function announce(message, assertiveness, timeout) {
|
|
104
|
-
if (assertiveness === void 0) {
|
|
105
|
-
assertiveness = 'assertive';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (timeout === void 0) {
|
|
109
|
-
timeout = $daf77d092755557a1dfdc345b21308d$var$LIVEREGION_TIMEOUT_DELAY;
|
|
110
|
-
}
|
|
111
126
|
|
|
112
|
-
|
|
127
|
+
$parcel$exportWildcard(module.exports, $97cebfa4133ebec3$exports);
|
|
113
128
|
|
|
114
|
-
if (assertiveness === 'assertive') {
|
|
115
|
-
setAssertiveMessages(messages => [...messages, {
|
|
116
|
-
id,
|
|
117
|
-
text: message
|
|
118
|
-
}]);
|
|
119
|
-
} else {
|
|
120
|
-
setPoliteMessages(messages => [...messages, {
|
|
121
|
-
id,
|
|
122
|
-
text: message
|
|
123
|
-
}]);
|
|
124
|
-
}
|
|
125
129
|
|
|
126
|
-
if (message !== '') {
|
|
127
|
-
setTimeout(() => {
|
|
128
|
-
if (assertiveness === 'assertive') {
|
|
129
|
-
setAssertiveMessages(messages => messages.filter(message => message.id !== id));
|
|
130
|
-
} else {
|
|
131
|
-
setPoliteMessages(messages => messages.filter(message => message.id !== id));
|
|
132
|
-
}
|
|
133
|
-
}, timeout);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
useImperativeHandle(ref, () => ({
|
|
138
|
-
announce,
|
|
139
|
-
clear
|
|
140
|
-
}));
|
|
141
|
-
return /*#__PURE__*/_react.createElement(Fragment, null, /*#__PURE__*/_react.createElement($daf77d092755557a1dfdc345b21308d$var$MessageBlock, {
|
|
142
|
-
"aria-live": "assertive"
|
|
143
|
-
}, assertiveMessages.map(message => /*#__PURE__*/_react.createElement("div", {
|
|
144
|
-
key: message.id
|
|
145
|
-
}, message.text))), /*#__PURE__*/_react.createElement($daf77d092755557a1dfdc345b21308d$var$MessageBlock, {
|
|
146
|
-
"aria-live": "polite"
|
|
147
|
-
}, politeMessages.map(message => /*#__PURE__*/_react.createElement("div", {
|
|
148
|
-
key: message.id
|
|
149
|
-
}, message.text))));
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
function $daf77d092755557a1dfdc345b21308d$var$MessageBlock(_ref) {
|
|
153
|
-
let {
|
|
154
|
-
children,
|
|
155
|
-
'aria-live': ariaLive
|
|
156
|
-
} = _ref;
|
|
157
|
-
return /*#__PURE__*/_react.createElement(VisuallyHidden, {
|
|
158
|
-
role: "log",
|
|
159
|
-
"aria-live": ariaLive,
|
|
160
|
-
"aria-relevant": "additions"
|
|
161
|
-
}, children);
|
|
162
|
-
}
|
|
163
130
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACsBA,EAAgE,AAAhE,4DAAgE,AAAhE,EAAgE,CAChE,KAAK,CAAC,8CAAwB,GAAG,IAAI;AAErC,GAAG,CAAC,yCAAmB,iBAAG,sCAAK,CAAC,SAAS;AACzC,GAAG,CAAC,0BAAI,GAAgB,IAAI;AAC5B,GAAG,CAAC,+BAAS,GAAG,CAAC;SAKD,yCAAQ,CACtB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I;2EAEtE,kCAAY;QAAC,CAAS,YAAC,CAAQ;OAC7B,cAAc,CAAC,GAAG,EAAC,OAAO,sEAAK,CAAG;YAAC,GAAG,EAAE,OAAO,CAAC,EAAE;WAAG,OAAO,CAAC,IAAI;;AAI1E,CAAC;SAOQ,kCAAY,CAAC,CAAC,WAAA,QAAQ,GAAE,CAAW,YAAE,QAAQ,EAAmB,CAAC,EAAE,CAAC;IAC3E,MAAM,oEACH,6CAAc;QACb,IAAI,EAAC,CAAK;QACV,CAAS,YAAE,QAAQ;QACnB,CAAa,gBAAC,CAAW;OACxB,QAAQ;AAGf,CAAC","sources":["packages/@react-aria/live-announcer/src/index.ts","packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './LiveAnnouncer';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport React, {Fragment, ReactNode, RefObject, useImperativeHandle, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport {VisuallyHidden} from '@react-aria/visually-hidden';\n\ntype Assertiveness = 'assertive' | 'polite';\ninterface Announcer {\n announce(message: string, assertiveness: Assertiveness, timeout: number): void,\n clear(assertiveness: Assertiveness): void\n}\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveRegionAnnouncer = React.createRef<Announcer>();\nlet node: HTMLElement = null;\nlet messageId = 0;\n\n/**\n * Announces the message using screen reader technology.\n */\nexport function announce(\n message: string,\n assertiveness: Assertiveness = 'assertive',\n timeout = LIVEREGION_TIMEOUT_DELAY\n) {\n ensureInstance(announcer => announcer.announce(message, assertiveness, timeout));\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness) {\n ensureInstance(announcer => announcer.clear(assertiveness));\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer() {\n if (liveRegionAnnouncer.current) {\n ReactDOM.unmountComponentAtNode(node);\n document.body.removeChild(node);\n node = null;\n }\n}\n\n/**\n * Ensures we only have one instance of the announcer so that we don't have elements competing.\n */\nfunction ensureInstance(callback: (announcer: Announcer) => void) {\n if (!liveRegionAnnouncer.current) {\n node = document.createElement('div');\n node.dataset.liveAnnouncer = 'true';\n document.body.prepend(node);\n ReactDOM.render(\n <LiveRegionAnnouncer ref={liveRegionAnnouncer} />,\n node,\n () => callback(liveRegionAnnouncer.current)\n );\n } else {\n callback(liveRegionAnnouncer.current);\n }\n}\n\nconst LiveRegionAnnouncer = React.forwardRef((_, ref: RefObject<Announcer>) => {\n let [assertiveMessages, setAssertiveMessages] = useState([]);\n let [politeMessages, setPoliteMessages] = useState([]);\n\n let clear = (assertiveness: Assertiveness) => {\n if (!assertiveness || assertiveness === 'assertive') {\n setAssertiveMessages([]);\n }\n\n if (!assertiveness || assertiveness === 'polite') {\n setPoliteMessages([]);\n }\n };\n\n let announce = (message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) => {\n let id = messageId++;\n\n if (assertiveness === 'assertive') {\n setAssertiveMessages(messages => [...messages, {id, text: message}]);\n } else {\n setPoliteMessages(messages => [...messages, {id, text: message}]);\n }\n\n if (message !== '') {\n setTimeout(() => {\n if (assertiveness === 'assertive') {\n setAssertiveMessages(messages => messages.filter(message => message.id !== id));\n } else {\n setPoliteMessages(messages => messages.filter(message => message.id !== id));\n }\n }, timeout);\n }\n };\n\n useImperativeHandle(ref, () => ({\n announce,\n clear\n }));\n\n return (\n <Fragment>\n <MessageBlock aria-live=\"assertive\">\n {assertiveMessages.map(message => <div key={message.id}>{message.text}</div>)}\n </MessageBlock>\n <MessageBlock aria-live=\"polite\">\n {politeMessages.map(message => <div key={message.id}>{message.text}</div>)}\n </MessageBlock>\n </Fragment>\n );\n});\n\ninterface MessageBlockProps {\n children: ReactNode,\n 'aria-live': Assertiveness\n }\n\nfunction MessageBlock({children, 'aria-live': ariaLive}: MessageBlockProps) {\n return (\n <VisuallyHidden\n role=\"log\"\n aria-live={ariaLive}\n aria-relevant=\"additions\">\n {children}\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,138 +1,111 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import $9Q8De$react, {useState as $9Q8De$useState, useImperativeHandle as $9Q8De$useImperativeHandle, Fragment as $9Q8De$Fragment} from "react";
|
|
2
|
+
import $9Q8De$reactdom from "react-dom";
|
|
3
|
+
import {VisuallyHidden as $9Q8De$VisuallyHidden} from "@react-aria/visually-hidden";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
var $319e236875307eab$exports = {};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Announces the message using screen reader technology.
|
|
14
|
-
*/
|
|
10
|
+
$parcel$export($319e236875307eab$exports, "announce", () => $319e236875307eab$export$a9b970dcc4ae71a9);
|
|
11
|
+
$parcel$export($319e236875307eab$exports, "clearAnnouncer", () => $319e236875307eab$export$d10ae4f68404609a);
|
|
12
|
+
$parcel$export($319e236875307eab$exports, "destroyAnnouncer", () => $319e236875307eab$export$d8686216b8b81b2f);
|
|
15
13
|
|
|
16
|
-
export function announce(message, assertiveness, timeout) {
|
|
17
|
-
if (assertiveness === void 0) {
|
|
18
|
-
assertiveness = 'assertive';
|
|
19
|
-
}
|
|
20
14
|
|
|
21
|
-
if (timeout === void 0) {
|
|
22
|
-
timeout = $de8b453f082d29ae3c4c121e2b261$var$LIVEREGION_TIMEOUT_DELAY;
|
|
23
|
-
}
|
|
24
15
|
|
|
25
|
-
|
|
16
|
+
/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
17
|
+
let $319e236875307eab$var$liveRegionAnnouncer = /*#__PURE__*/ $9Q8De$react.createRef();
|
|
18
|
+
let $319e236875307eab$var$node = null;
|
|
19
|
+
let $319e236875307eab$var$messageId = 0;
|
|
20
|
+
function $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
21
|
+
$319e236875307eab$var$ensureInstance((announcer)=>announcer.announce(message, assertiveness, timeout)
|
|
22
|
+
);
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export function clearAnnouncer(assertiveness) {
|
|
32
|
-
$de8b453f082d29ae3c4c121e2b261$var$ensureInstance(announcer => announcer.clear(assertiveness));
|
|
24
|
+
function $319e236875307eab$export$d10ae4f68404609a(assertiveness) {
|
|
25
|
+
$319e236875307eab$var$ensureInstance((announcer)=>announcer.clear(assertiveness)
|
|
26
|
+
);
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
_reactDom.unmountComponentAtNode($de8b453f082d29ae3c4c121e2b261$var$node);
|
|
41
|
-
|
|
42
|
-
document.body.removeChild($de8b453f082d29ae3c4c121e2b261$var$node);
|
|
43
|
-
$de8b453f082d29ae3c4c121e2b261$var$node = null;
|
|
44
|
-
}
|
|
28
|
+
function $319e236875307eab$export$d8686216b8b81b2f() {
|
|
29
|
+
if ($319e236875307eab$var$liveRegionAnnouncer.current) {
|
|
30
|
+
$9Q8De$reactdom.unmountComponentAtNode($319e236875307eab$var$node);
|
|
31
|
+
document.body.removeChild($319e236875307eab$var$node);
|
|
32
|
+
$319e236875307eab$var$node = null;
|
|
33
|
+
}
|
|
45
34
|
}
|
|
46
35
|
/**
|
|
47
36
|
* Ensures we only have one instance of the announcer so that we don't have elements competing.
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
37
|
+
*/ function $319e236875307eab$var$ensureInstance(callback) {
|
|
38
|
+
if (!$319e236875307eab$var$liveRegionAnnouncer.current) {
|
|
39
|
+
$319e236875307eab$var$node = document.createElement('div');
|
|
40
|
+
$319e236875307eab$var$node.dataset.liveAnnouncer = 'true';
|
|
41
|
+
document.body.prepend($319e236875307eab$var$node);
|
|
42
|
+
$9Q8De$reactdom.render(/*#__PURE__*/ $9Q8De$react.createElement($319e236875307eab$var$LiveRegionAnnouncer, {
|
|
43
|
+
ref: $319e236875307eab$var$liveRegionAnnouncer
|
|
44
|
+
}), $319e236875307eab$var$node, ()=>callback($319e236875307eab$var$liveRegionAnnouncer.current)
|
|
45
|
+
);
|
|
46
|
+
} else callback($319e236875307eab$var$liveRegionAnnouncer.current);
|
|
47
|
+
}
|
|
48
|
+
const $319e236875307eab$var$LiveRegionAnnouncer = /*#__PURE__*/ $9Q8De$react.forwardRef((_, ref)=>{
|
|
49
|
+
let [assertiveMessages, setAssertiveMessages] = $9Q8De$useState([]);
|
|
50
|
+
let [politeMessages, setPoliteMessages] = $9Q8De$useState([]);
|
|
51
|
+
let clear = (assertiveness)=>{
|
|
52
|
+
if (!assertiveness || assertiveness === 'assertive') setAssertiveMessages([]);
|
|
53
|
+
if (!assertiveness || assertiveness === 'polite') setPoliteMessages([]);
|
|
54
|
+
};
|
|
55
|
+
let $319e236875307eab$export$a9b970dcc4ae71a9 = (message1, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY)=>{
|
|
56
|
+
let id = $319e236875307eab$var$messageId++;
|
|
57
|
+
if (assertiveness === 'assertive') setAssertiveMessages((messages)=>[
|
|
58
|
+
...messages,
|
|
59
|
+
{
|
|
60
|
+
id: id,
|
|
61
|
+
text: message1
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
);
|
|
65
|
+
else setPoliteMessages((messages)=>[
|
|
66
|
+
...messages,
|
|
67
|
+
{
|
|
68
|
+
id: id,
|
|
69
|
+
text: message1
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
);
|
|
73
|
+
if (message1 !== '') setTimeout(()=>{
|
|
74
|
+
if (assertiveness === 'assertive') setAssertiveMessages((messages)=>messages.filter((message)=>message.id !== id
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
else setPoliteMessages((messages)=>messages.filter((message)=>message.id !== id
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
}, timeout);
|
|
81
|
+
};
|
|
82
|
+
$9Q8De$useImperativeHandle(ref, ()=>({
|
|
83
|
+
announce: $319e236875307eab$export$a9b970dcc4ae71a9,
|
|
84
|
+
clear: clear
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
return(/*#__PURE__*/ $9Q8De$react.createElement($9Q8De$Fragment, null, /*#__PURE__*/ $9Q8De$react.createElement($319e236875307eab$var$MessageBlock, {
|
|
88
|
+
"aria-live": "assertive"
|
|
89
|
+
}, assertiveMessages.map((message)=>/*#__PURE__*/ $9Q8De$react.createElement("div", {
|
|
90
|
+
key: message.id
|
|
91
|
+
}, message.text)
|
|
92
|
+
)), /*#__PURE__*/ $9Q8De$react.createElement($319e236875307eab$var$MessageBlock, {
|
|
93
|
+
"aria-live": "polite"
|
|
94
|
+
}, politeMessages.map((message)=>/*#__PURE__*/ $9Q8De$react.createElement("div", {
|
|
95
|
+
key: message.id
|
|
96
|
+
}, message.text)
|
|
97
|
+
))));
|
|
98
|
+
});
|
|
99
|
+
function $319e236875307eab$var$MessageBlock({ children: children , 'aria-live': ariaLive }) {
|
|
100
|
+
return(/*#__PURE__*/ $9Q8De$react.createElement($9Q8De$VisuallyHidden, {
|
|
101
|
+
role: "log",
|
|
102
|
+
"aria-live": ariaLive,
|
|
103
|
+
"aria-relevant": "additions"
|
|
104
|
+
}, children));
|
|
62
105
|
}
|
|
63
106
|
|
|
64
|
-
const $de8b453f082d29ae3c4c121e2b261$var$LiveRegionAnnouncer = /*#__PURE__*/_react.forwardRef((_, ref) => {
|
|
65
|
-
let [assertiveMessages, setAssertiveMessages] = useState([]);
|
|
66
|
-
let [politeMessages, setPoliteMessages] = useState([]);
|
|
67
|
-
|
|
68
|
-
let clear = assertiveness => {
|
|
69
|
-
if (!assertiveness || assertiveness === 'assertive') {
|
|
70
|
-
setAssertiveMessages([]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!assertiveness || assertiveness === 'polite') {
|
|
74
|
-
setPoliteMessages([]);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
let announce = function announce(message, assertiveness, timeout) {
|
|
79
|
-
if (assertiveness === void 0) {
|
|
80
|
-
assertiveness = 'assertive';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (timeout === void 0) {
|
|
84
|
-
timeout = $de8b453f082d29ae3c4c121e2b261$var$LIVEREGION_TIMEOUT_DELAY;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let id = $de8b453f082d29ae3c4c121e2b261$var$messageId++;
|
|
88
|
-
|
|
89
|
-
if (assertiveness === 'assertive') {
|
|
90
|
-
setAssertiveMessages(messages => [...messages, {
|
|
91
|
-
id,
|
|
92
|
-
text: message
|
|
93
|
-
}]);
|
|
94
|
-
} else {
|
|
95
|
-
setPoliteMessages(messages => [...messages, {
|
|
96
|
-
id,
|
|
97
|
-
text: message
|
|
98
|
-
}]);
|
|
99
|
-
}
|
|
100
107
|
|
|
101
|
-
if (message !== '') {
|
|
102
|
-
setTimeout(() => {
|
|
103
|
-
if (assertiveness === 'assertive') {
|
|
104
|
-
setAssertiveMessages(messages => messages.filter(message => message.id !== id));
|
|
105
|
-
} else {
|
|
106
|
-
setPoliteMessages(messages => messages.filter(message => message.id !== id));
|
|
107
|
-
}
|
|
108
|
-
}, timeout);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
108
|
|
|
112
|
-
useImperativeHandle(ref, () => ({
|
|
113
|
-
announce,
|
|
114
|
-
clear
|
|
115
|
-
}));
|
|
116
|
-
return /*#__PURE__*/_react.createElement(Fragment, null, /*#__PURE__*/_react.createElement($de8b453f082d29ae3c4c121e2b261$var$MessageBlock, {
|
|
117
|
-
"aria-live": "assertive"
|
|
118
|
-
}, assertiveMessages.map(message => /*#__PURE__*/_react.createElement("div", {
|
|
119
|
-
key: message.id
|
|
120
|
-
}, message.text))), /*#__PURE__*/_react.createElement($de8b453f082d29ae3c4c121e2b261$var$MessageBlock, {
|
|
121
|
-
"aria-live": "polite"
|
|
122
|
-
}, politeMessages.map(message => /*#__PURE__*/_react.createElement("div", {
|
|
123
|
-
key: message.id
|
|
124
|
-
}, message.text))));
|
|
125
|
-
});
|
|
126
109
|
|
|
127
|
-
|
|
128
|
-
let {
|
|
129
|
-
children,
|
|
130
|
-
'aria-live': ariaLive
|
|
131
|
-
} = _ref;
|
|
132
|
-
return /*#__PURE__*/_react.createElement(VisuallyHidden, {
|
|
133
|
-
role: "log",
|
|
134
|
-
"aria-live": ariaLive,
|
|
135
|
-
"aria-relevant": "additions"
|
|
136
|
-
}, children);
|
|
137
|
-
}
|
|
110
|
+
export {$319e236875307eab$export$a9b970dcc4ae71a9 as announce, $319e236875307eab$export$d10ae4f68404609a as clearAnnouncer, $319e236875307eab$export$d8686216b8b81b2f as destroyAnnouncer};
|
|
138
111
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;ACsBA,EAAgE,AAAhE,4DAAgE,AAAhE,EAAgE,CAChE,KAAK,CAAC,8CAAwB,GAAG,IAAI;AAErC,GAAG,CAAC,yCAAmB,iBAAG,YAAK,CAAC,SAAS;AACzC,GAAG,CAAC,0BAAI,GAAgB,IAAI;AAC5B,GAAG,CAAC,+BAAS,GAAG,CAAC;SAKD,yCAAQ,CACtB,OAAe,EACf,aAA4B,GAAG,CAAW,YAC1C,OAAO,GAAG,8CAAwB,EAClC,CAAC;IACD,oCAAc,EAAC,SAAS,GAAI,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO;;AAChF,CAAC;SAKe,yCAAc,CAAC,aAA4B,EAAE,CAAC;IAC5D,oCAAc,EAAC,SAAS,GAAI,SAAS,CAAC,KAAK,CAAC,aAAa;;AAC3D,CAAC;SAKe,yCAAgB,GAAG,CAAC;IAClC,EAAE,EAAE,yCAAmB,CAAC,OAAO,EAAE,CAAC;QAChC,eAAQ,CAAC,sBAAsB,CAAC,0BAAI;QACpC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,0BAAI;QAC9B,0BAAI,GAAG,IAAI;IACb,CAAC;AACH,CAAC;AAED,EAEG,AAFH;;CAEG,AAFH,EAEG,UACM,oCAAc,CAAC,QAAwC,EAAE,CAAC;IACjE,EAAE,GAAG,yCAAmB,CAAC,OAAO,EAAE,CAAC;QACjC,0B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lE,EAAE,EAAE,QAAO,KAAK,CAAE,GAChB,UAAU,KAAO,CAAC;YAChB,EAAE,EAAE,aAAa,KAAK,CAAW,YAC/B,oBAAoB,EAAC,QAAQ,GAAI,QAAQ,CAAC,MAAM,EAAC,OAAO,GAAI,OAAO,CAAC,EAAE,KAAK,EAAE;;;iBAE7E,iBAAiB,EAAC,QAAQ,GAAI,QAAQ,CAAC,MAAM,EAAC,OAAO,GAAI,OAAO,CAAC,EAAE,KAAK,EAAE;;;QAE9E,CAAC,EAAE,OAAO;IAEd,CAAC;IAED,0BAAmB,CAAC,GAAG,OAAS,CAAC;sBAC/B,yCAAQ;mBACR,KAAK;QACP,CAAC;;IAED,MAAM,0CACH,eAAQ,iDACN,kCAAY;QAAC,CAAS,YAAC,CAAW;OAChC,iBAAiB,CAAC,GAAG,EAAC,OAAO,4CAAK,CAAG;YAAC,GAAG,EAAE,OAAO,CAAC,EAAE;WAAG,OAAO,CAAC,IAAI;iDAEtE,kCAAY;QAAC,CAAS,YAAC,CAAQ;OAC7B,cAAc,CAAC,GAAG,EAAC,OAAO,4CAAK,CAAG;YAAC,GAAG,EAAE,OAAO,CAAC,EAAE;WAAG,OAAO,CAAC,IAAI;;AAI1E,CAAC;SAOQ,kCAAY,CAAC,CAAC,WAAA,QAAQ,GAAE,CAAW,YAAE,QAAQ,EAAmB,CAAC,EAAE,CAAC;IAC3E,MAAM,0CACH,qBAAc;QACb,IAAI,EAAC,CAAK;QACV,CAAS,YAAE,QAAQ;QACnB,CAAa,gBAAC,CAAW;OACxB,QAAQ;AAGf,CAAC","sources":["packages/@react-aria/live-announcer/src/index.ts","packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './LiveAnnouncer';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport React, {Fragment, ReactNode, RefObject, useImperativeHandle, useState} from 'react';\nimport ReactDOM from 'react-dom';\nimport {VisuallyHidden} from '@react-aria/visually-hidden';\n\ntype Assertiveness = 'assertive' | 'polite';\ninterface Announcer {\n announce(message: string, assertiveness: Assertiveness, timeout: number): void,\n clear(assertiveness: Assertiveness): void\n}\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveRegionAnnouncer = React.createRef<Announcer>();\nlet node: HTMLElement = null;\nlet messageId = 0;\n\n/**\n * Announces the message using screen reader technology.\n */\nexport function announce(\n message: string,\n assertiveness: Assertiveness = 'assertive',\n timeout = LIVEREGION_TIMEOUT_DELAY\n) {\n ensureInstance(announcer => announcer.announce(message, assertiveness, timeout));\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness) {\n ensureInstance(announcer => announcer.clear(assertiveness));\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer() {\n if (liveRegionAnnouncer.current) {\n ReactDOM.unmountComponentAtNode(node);\n document.body.removeChild(node);\n node = null;\n }\n}\n\n/**\n * Ensures we only have one instance of the announcer so that we don't have elements competing.\n */\nfunction ensureInstance(callback: (announcer: Announcer) => void) {\n if (!liveRegionAnnouncer.current) {\n node = document.createElement('div');\n node.dataset.liveAnnouncer = 'true';\n document.body.prepend(node);\n ReactDOM.render(\n <LiveRegionAnnouncer ref={liveRegionAnnouncer} />,\n node,\n () => callback(liveRegionAnnouncer.current)\n );\n } else {\n callback(liveRegionAnnouncer.current);\n }\n}\n\nconst LiveRegionAnnouncer = React.forwardRef((_, ref: RefObject<Announcer>) => {\n let [assertiveMessages, setAssertiveMessages] = useState([]);\n let [politeMessages, setPoliteMessages] = useState([]);\n\n let clear = (assertiveness: Assertiveness) => {\n if (!assertiveness || assertiveness === 'assertive') {\n setAssertiveMessages([]);\n }\n\n if (!assertiveness || assertiveness === 'polite') {\n setPoliteMessages([]);\n }\n };\n\n let announce = (message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) => {\n let id = messageId++;\n\n if (assertiveness === 'assertive') {\n setAssertiveMessages(messages => [...messages, {id, text: message}]);\n } else {\n setPoliteMessages(messages => [...messages, {id, text: message}]);\n }\n\n if (message !== '') {\n setTimeout(() => {\n if (assertiveness === 'assertive') {\n setAssertiveMessages(messages => messages.filter(message => message.id !== id));\n } else {\n setPoliteMessages(messages => messages.filter(message => message.id !== id));\n }\n }, timeout);\n }\n };\n\n useImperativeHandle(ref, () => ({\n announce,\n clear\n }));\n\n return (\n <Fragment>\n <MessageBlock aria-live=\"assertive\">\n {assertiveMessages.map(message => <div key={message.id}>{message.text}</div>)}\n </MessageBlock>\n <MessageBlock aria-live=\"polite\">\n {politeMessages.map(message => <div key={message.id}>{message.text}</div>)}\n </MessageBlock>\n </Fragment>\n );\n});\n\ninterface MessageBlockProps {\n children: ReactNode,\n 'aria-live': Assertiveness\n }\n\nfunction MessageBlock({children, 'aria-live': ariaLive}: MessageBlockProps) {\n return (\n <VisuallyHidden\n role=\"log\"\n aria-live={ariaLive}\n aria-relevant=\"additions\">\n {children}\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAgBA,qBAAqB,WAAW,GAAG,QAAQ,CAAC;AAa5C
|
|
1
|
+
{"mappings":"AAgBA,qBAAqB,WAAW,GAAG,QAAQ,CAAC;AAa5C;;GAEG;AACH,yBACE,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,aAA2B,EAC1C,OAAO,SAA2B,QAGnC;AAED;;GAEG;AACH,+BAA+B,aAAa,EAAE,aAAa,QAE1D;AAED;;GAEG;AACH,yCAMC","sources":["packages/@react-aria/live-announcer/src/packages/@react-aria/live-announcer/src/LiveAnnouncer.tsx","packages/@react-aria/live-announcer/src/packages/@react-aria/live-announcer/src/index.ts","packages/@react-aria/live-announcer/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './LiveAnnouncer';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/live-announcer",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/utils": "^3.
|
|
22
|
-
"@react-aria/visually-hidden": "^3.2.
|
|
21
|
+
"@react-aria/utils": "^3.11.3",
|
|
22
|
+
"@react-aria/visually-hidden": "^3.2.6"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": "^16.8.0 || ^17.0.0-rc.1",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "ed8d8d984c2f7f2c31e8b18795b97858a95e4729"
|
|
32
32
|
}
|