@react-aria/live-announcer 3.0.6 → 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/dist/main.js +62 -90
- package/dist/main.js.map +1 -1
- package/dist/module.js +62 -87
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -9
- package/src/LiveAnnouncer.tsx +84 -84
package/dist/main.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
var $9snhK$react = require("react");
|
|
2
|
-
var $9snhK$reactdom = require("react-dom");
|
|
3
|
-
var $9snhK$reactariavisuallyhidden = require("@react-aria/visually-hidden");
|
|
4
|
-
|
|
5
1
|
function $parcel$exportWildcard(dest, source) {
|
|
6
2
|
Object.keys(source).forEach(function(key) {
|
|
7
3
|
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
@@ -18,9 +14,6 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
18
14
|
|
|
19
15
|
return dest;
|
|
20
16
|
}
|
|
21
|
-
function $parcel$interopDefault(a) {
|
|
22
|
-
return a && a.__esModule ? a.default : a;
|
|
23
|
-
}
|
|
24
17
|
function $parcel$export(e, n, v, s) {
|
|
25
18
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
26
19
|
}
|
|
@@ -29,98 +22,77 @@ var $97cebfa4133ebec3$exports = {};
|
|
|
29
22
|
$parcel$export($97cebfa4133ebec3$exports, "announce", () => $97cebfa4133ebec3$export$a9b970dcc4ae71a9);
|
|
30
23
|
$parcel$export($97cebfa4133ebec3$exports, "clearAnnouncer", () => $97cebfa4133ebec3$export$d10ae4f68404609a);
|
|
31
24
|
$parcel$export($97cebfa4133ebec3$exports, "destroyAnnouncer", () => $97cebfa4133ebec3$export$d8686216b8b81b2f);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
25
|
/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
36
|
-
let $97cebfa4133ebec3$var$
|
|
37
|
-
let $97cebfa4133ebec3$var$node = null;
|
|
38
|
-
let $97cebfa4133ebec3$var$messageId = 0;
|
|
26
|
+
let $97cebfa4133ebec3$var$liveAnnouncer = null;
|
|
39
27
|
function $97cebfa4133ebec3$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
40
|
-
|
|
41
|
-
);
|
|
28
|
+
if (!$97cebfa4133ebec3$var$liveAnnouncer) $97cebfa4133ebec3$var$liveAnnouncer = new $97cebfa4133ebec3$var$LiveAnnouncer();
|
|
29
|
+
$97cebfa4133ebec3$var$liveAnnouncer.announce(message, assertiveness, timeout);
|
|
42
30
|
}
|
|
43
31
|
function $97cebfa4133ebec3$export$d10ae4f68404609a(assertiveness) {
|
|
44
|
-
$97cebfa4133ebec3$var$
|
|
45
|
-
);
|
|
32
|
+
if ($97cebfa4133ebec3$var$liveAnnouncer) $97cebfa4133ebec3$var$liveAnnouncer.clear(assertiveness);
|
|
46
33
|
}
|
|
47
34
|
function $97cebfa4133ebec3$export$d8686216b8b81b2f() {
|
|
48
|
-
if ($97cebfa4133ebec3$var$
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
$97cebfa4133ebec3$var$node = null;
|
|
35
|
+
if ($97cebfa4133ebec3$var$liveAnnouncer) {
|
|
36
|
+
$97cebfa4133ebec3$var$liveAnnouncer.destroy();
|
|
37
|
+
$97cebfa4133ebec3$var$liveAnnouncer = null;
|
|
52
38
|
}
|
|
53
39
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
);
|
|
40
|
+
// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
|
|
41
|
+
// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
|
|
42
|
+
// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
|
|
43
|
+
// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
|
|
44
|
+
// is simple enough to implement without React, so that's what we do here.
|
|
45
|
+
// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
|
|
46
|
+
class $97cebfa4133ebec3$var$LiveAnnouncer {
|
|
47
|
+
createLog(ariaLive) {
|
|
48
|
+
let node = document.createElement('div');
|
|
49
|
+
node.setAttribute('role', 'log');
|
|
50
|
+
node.setAttribute('aria-live', ariaLive);
|
|
51
|
+
node.setAttribute('aria-relevant', 'additions');
|
|
52
|
+
return node;
|
|
53
|
+
}
|
|
54
|
+
destroy() {
|
|
55
|
+
if (!this.node) return;
|
|
56
|
+
document.body.removeChild(this.node);
|
|
57
|
+
this.node = null;
|
|
58
|
+
}
|
|
59
|
+
announce(message, assertiveness = 'assertive', timeout = $97cebfa4133ebec3$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
60
|
+
if (!this.node) return;
|
|
61
|
+
let node = document.createElement('div');
|
|
62
|
+
node.textContent = message;
|
|
63
|
+
if (assertiveness === 'assertive') this.assertiveLog.appendChild(node);
|
|
64
|
+
else this.politeLog.appendChild(node);
|
|
65
|
+
if (message !== '') setTimeout(()=>{
|
|
66
|
+
node.remove();
|
|
99
67
|
}, timeout);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
68
|
+
}
|
|
69
|
+
clear(assertiveness) {
|
|
70
|
+
if (!this.node) return;
|
|
71
|
+
if (!assertiveness || assertiveness === 'assertive') this.assertiveLog.innerHTML = '';
|
|
72
|
+
if (!assertiveness || assertiveness === 'polite') this.politeLog.innerHTML = '';
|
|
73
|
+
}
|
|
74
|
+
constructor(){
|
|
75
|
+
this.node = document.createElement('div');
|
|
76
|
+
this.node.dataset.liveAnnouncer = 'true';
|
|
77
|
+
// copied from VisuallyHidden
|
|
78
|
+
Object.assign(this.node.style, {
|
|
79
|
+
border: 0,
|
|
80
|
+
clip: 'rect(0 0 0 0)',
|
|
81
|
+
clipPath: 'inset(50%)',
|
|
82
|
+
height: 1,
|
|
83
|
+
margin: '0 -1px -1px 0',
|
|
84
|
+
overflow: 'hidden',
|
|
85
|
+
padding: 0,
|
|
86
|
+
position: 'absolute',
|
|
87
|
+
width: 1,
|
|
88
|
+
whiteSpace: 'nowrap'
|
|
89
|
+
});
|
|
90
|
+
this.assertiveLog = this.createLog('assertive');
|
|
91
|
+
this.node.appendChild(this.assertiveLog);
|
|
92
|
+
this.politeLog = this.createLog('polite');
|
|
93
|
+
this.node.appendChild(this.politeLog);
|
|
94
|
+
document.body.prepend(this.node);
|
|
95
|
+
}
|
|
124
96
|
}
|
|
125
97
|
|
|
126
98
|
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"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","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\ntype Assertiveness = 'assertive' | 'polite';\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveAnnouncer: LiveAnnouncer = null;\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 if (!liveAnnouncer) {\n liveAnnouncer = new LiveAnnouncer();\n }\n\n liveAnnouncer.announce(message, assertiveness, timeout);\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness) {\n if (liveAnnouncer) {\n liveAnnouncer.clear(assertiveness);\n }\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer() {\n if (liveAnnouncer) {\n liveAnnouncer.destroy();\n liveAnnouncer = null;\n }\n}\n\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass LiveAnnouncer {\n node: HTMLElement;\n assertiveLog: HTMLElement;\n politeLog: HTMLElement;\n\n constructor() {\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: 1,\n margin: '0 -1px -1px 0',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: 1,\n whiteSpace: 'nowrap'\n });\n\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n\n document.body.prepend(this.node);\n }\n\n createLog(ariaLive: string) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n\n destroy() {\n if (!this.node) {\n return;\n }\n\n document.body.removeChild(this.node);\n this.node = null;\n }\n\n announce(message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) {\n return;\n }\n\n let node = document.createElement('div');\n node.textContent = message;\n\n if (assertiveness === 'assertive') {\n this.assertiveLog.appendChild(node);\n } else {\n this.politeLog.appendChild(node);\n }\n\n if (message !== '') {\n setTimeout(() => {\n node.remove();\n }, timeout);\n }\n }\n\n clear(assertiveness: Assertiveness) {\n if (!this.node) {\n return;\n }\n\n if (!assertiveness || assertiveness === 'assertive') {\n this.assertiveLog.innerHTML = '';\n }\n\n if (!assertiveness || assertiveness === 'polite') {\n this.politeLog.innerHTML = '';\n }\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
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
|
-
|
|
5
1
|
function $parcel$export(e, n, v, s) {
|
|
6
2
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
3
|
}
|
|
@@ -10,98 +6,77 @@ var $319e236875307eab$exports = {};
|
|
|
10
6
|
$parcel$export($319e236875307eab$exports, "announce", () => $319e236875307eab$export$a9b970dcc4ae71a9);
|
|
11
7
|
$parcel$export($319e236875307eab$exports, "clearAnnouncer", () => $319e236875307eab$export$d10ae4f68404609a);
|
|
12
8
|
$parcel$export($319e236875307eab$exports, "destroyAnnouncer", () => $319e236875307eab$export$d8686216b8b81b2f);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
9
|
/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */ const $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
17
|
-
let $319e236875307eab$var$
|
|
18
|
-
let $319e236875307eab$var$node = null;
|
|
19
|
-
let $319e236875307eab$var$messageId = 0;
|
|
10
|
+
let $319e236875307eab$var$liveAnnouncer = null;
|
|
20
11
|
function $319e236875307eab$export$a9b970dcc4ae71a9(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
21
|
-
|
|
22
|
-
);
|
|
12
|
+
if (!$319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer = new $319e236875307eab$var$LiveAnnouncer();
|
|
13
|
+
$319e236875307eab$var$liveAnnouncer.announce(message, assertiveness, timeout);
|
|
23
14
|
}
|
|
24
15
|
function $319e236875307eab$export$d10ae4f68404609a(assertiveness) {
|
|
25
|
-
$319e236875307eab$var$
|
|
26
|
-
);
|
|
16
|
+
if ($319e236875307eab$var$liveAnnouncer) $319e236875307eab$var$liveAnnouncer.clear(assertiveness);
|
|
27
17
|
}
|
|
28
18
|
function $319e236875307eab$export$d8686216b8b81b2f() {
|
|
29
|
-
if ($319e236875307eab$var$
|
|
30
|
-
$
|
|
31
|
-
|
|
32
|
-
$319e236875307eab$var$node = null;
|
|
19
|
+
if ($319e236875307eab$var$liveAnnouncer) {
|
|
20
|
+
$319e236875307eab$var$liveAnnouncer.destroy();
|
|
21
|
+
$319e236875307eab$var$liveAnnouncer = null;
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
);
|
|
24
|
+
// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
|
|
25
|
+
// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
|
|
26
|
+
// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
|
|
27
|
+
// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
|
|
28
|
+
// is simple enough to implement without React, so that's what we do here.
|
|
29
|
+
// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
|
|
30
|
+
class $319e236875307eab$var$LiveAnnouncer {
|
|
31
|
+
createLog(ariaLive) {
|
|
32
|
+
let node = document.createElement('div');
|
|
33
|
+
node.setAttribute('role', 'log');
|
|
34
|
+
node.setAttribute('aria-live', ariaLive);
|
|
35
|
+
node.setAttribute('aria-relevant', 'additions');
|
|
36
|
+
return node;
|
|
37
|
+
}
|
|
38
|
+
destroy() {
|
|
39
|
+
if (!this.node) return;
|
|
40
|
+
document.body.removeChild(this.node);
|
|
41
|
+
this.node = null;
|
|
42
|
+
}
|
|
43
|
+
announce(message, assertiveness = 'assertive', timeout = $319e236875307eab$var$LIVEREGION_TIMEOUT_DELAY) {
|
|
44
|
+
if (!this.node) return;
|
|
45
|
+
let node = document.createElement('div');
|
|
46
|
+
node.textContent = message;
|
|
47
|
+
if (assertiveness === 'assertive') this.assertiveLog.appendChild(node);
|
|
48
|
+
else this.politeLog.appendChild(node);
|
|
49
|
+
if (message !== '') setTimeout(()=>{
|
|
50
|
+
node.remove();
|
|
80
51
|
}, timeout);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
52
|
+
}
|
|
53
|
+
clear(assertiveness) {
|
|
54
|
+
if (!this.node) return;
|
|
55
|
+
if (!assertiveness || assertiveness === 'assertive') this.assertiveLog.innerHTML = '';
|
|
56
|
+
if (!assertiveness || assertiveness === 'polite') this.politeLog.innerHTML = '';
|
|
57
|
+
}
|
|
58
|
+
constructor(){
|
|
59
|
+
this.node = document.createElement('div');
|
|
60
|
+
this.node.dataset.liveAnnouncer = 'true';
|
|
61
|
+
// copied from VisuallyHidden
|
|
62
|
+
Object.assign(this.node.style, {
|
|
63
|
+
border: 0,
|
|
64
|
+
clip: 'rect(0 0 0 0)',
|
|
65
|
+
clipPath: 'inset(50%)',
|
|
66
|
+
height: 1,
|
|
67
|
+
margin: '0 -1px -1px 0',
|
|
68
|
+
overflow: 'hidden',
|
|
69
|
+
padding: 0,
|
|
70
|
+
position: 'absolute',
|
|
71
|
+
width: 1,
|
|
72
|
+
whiteSpace: 'nowrap'
|
|
73
|
+
});
|
|
74
|
+
this.assertiveLog = this.createLog('assertive');
|
|
75
|
+
this.node.appendChild(this.assertiveLog);
|
|
76
|
+
this.politeLog = this.createLog('polite');
|
|
77
|
+
this.node.appendChild(this.politeLog);
|
|
78
|
+
document.body.prepend(this.node);
|
|
79
|
+
}
|
|
105
80
|
}
|
|
106
81
|
|
|
107
82
|
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"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","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\ntype Assertiveness = 'assertive' | 'polite';\n\n/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */\nconst LIVEREGION_TIMEOUT_DELAY = 7000;\n\nlet liveAnnouncer: LiveAnnouncer = null;\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 if (!liveAnnouncer) {\n liveAnnouncer = new LiveAnnouncer();\n }\n\n liveAnnouncer.announce(message, assertiveness, timeout);\n}\n\n/**\n * Stops all queued announcements.\n */\nexport function clearAnnouncer(assertiveness: Assertiveness) {\n if (liveAnnouncer) {\n liveAnnouncer.clear(assertiveness);\n }\n}\n\n/**\n * Removes the announcer from the DOM.\n */\nexport function destroyAnnouncer() {\n if (liveAnnouncer) {\n liveAnnouncer.destroy();\n liveAnnouncer = null;\n }\n}\n\n// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18\n// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a\n// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.\n// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer\n// is simple enough to implement without React, so that's what we do here.\n// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638\nclass LiveAnnouncer {\n node: HTMLElement;\n assertiveLog: HTMLElement;\n politeLog: HTMLElement;\n\n constructor() {\n this.node = document.createElement('div');\n this.node.dataset.liveAnnouncer = 'true';\n // copied from VisuallyHidden\n Object.assign(this.node.style, {\n border: 0,\n clip: 'rect(0 0 0 0)',\n clipPath: 'inset(50%)',\n height: 1,\n margin: '0 -1px -1px 0',\n overflow: 'hidden',\n padding: 0,\n position: 'absolute',\n width: 1,\n whiteSpace: 'nowrap'\n });\n\n this.assertiveLog = this.createLog('assertive');\n this.node.appendChild(this.assertiveLog);\n\n this.politeLog = this.createLog('polite');\n this.node.appendChild(this.politeLog);\n\n document.body.prepend(this.node);\n }\n\n createLog(ariaLive: string) {\n let node = document.createElement('div');\n node.setAttribute('role', 'log');\n node.setAttribute('aria-live', ariaLive);\n node.setAttribute('aria-relevant', 'additions');\n return node;\n }\n\n destroy() {\n if (!this.node) {\n return;\n }\n\n document.body.removeChild(this.node);\n this.node = null;\n }\n\n announce(message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {\n if (!this.node) {\n return;\n }\n\n let node = document.createElement('div');\n node.textContent = message;\n\n if (assertiveness === 'assertive') {\n this.assertiveLog.appendChild(node);\n } else {\n this.politeLog.appendChild(node);\n }\n\n if (message !== '') {\n setTimeout(() => {\n node.remove();\n }, timeout);\n }\n }\n\n clear(assertiveness: Assertiveness) {\n if (!this.node) {\n return;\n }\n\n if (!assertiveness || assertiveness === 'assertive') {\n this.assertiveLog.innerHTML = '';\n }\n\n if (!assertiveness || assertiveness === 'polite') {\n this.politeLog.innerHTML = '';\n }\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAYA,qBAAqB,WAAW,GAAG,QAAQ,CAAC;AAO5C;;GAEG;AACH,yBACE,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,aAA2B,EAC1C,OAAO,SAA2B,QAOnC;AAED;;GAEG;AACH,+BAA+B,aAAa,EAAE,aAAa,QAI1D;AAED;;GAEG;AACH,yCAKC","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.1.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -17,16 +17,10 @@
|
|
|
17
17
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@babel/runtime": "^7.6.2"
|
|
21
|
-
"@react-aria/utils": "^3.12.0",
|
|
22
|
-
"@react-aria/visually-hidden": "^3.2.8"
|
|
23
|
-
},
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"react": "^16.8.0 || ^17.0.0-rc.1",
|
|
26
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1"
|
|
20
|
+
"@babel/runtime": "^7.6.2"
|
|
27
21
|
},
|
|
28
22
|
"publishConfig": {
|
|
29
23
|
"access": "public"
|
|
30
24
|
},
|
|
31
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
|
|
32
26
|
}
|
package/src/LiveAnnouncer.tsx
CHANGED
|
@@ -10,22 +10,12 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import React, {Fragment, ReactNode, RefObject, useImperativeHandle, useState} from 'react';
|
|
14
|
-
import ReactDOM from 'react-dom';
|
|
15
|
-
import {VisuallyHidden} from '@react-aria/visually-hidden';
|
|
16
|
-
|
|
17
13
|
type Assertiveness = 'assertive' | 'polite';
|
|
18
|
-
interface Announcer {
|
|
19
|
-
announce(message: string, assertiveness: Assertiveness, timeout: number): void,
|
|
20
|
-
clear(assertiveness: Assertiveness): void
|
|
21
|
-
}
|
|
22
14
|
|
|
23
15
|
/* Inspired by https://github.com/AlmeroSteyn/react-aria-live */
|
|
24
16
|
const LIVEREGION_TIMEOUT_DELAY = 7000;
|
|
25
17
|
|
|
26
|
-
let
|
|
27
|
-
let node: HTMLElement = null;
|
|
28
|
-
let messageId = 0;
|
|
18
|
+
let liveAnnouncer: LiveAnnouncer = null;
|
|
29
19
|
|
|
30
20
|
/**
|
|
31
21
|
* Announces the message using screen reader technology.
|
|
@@ -35,108 +25,118 @@ export function announce(
|
|
|
35
25
|
assertiveness: Assertiveness = 'assertive',
|
|
36
26
|
timeout = LIVEREGION_TIMEOUT_DELAY
|
|
37
27
|
) {
|
|
38
|
-
|
|
28
|
+
if (!liveAnnouncer) {
|
|
29
|
+
liveAnnouncer = new LiveAnnouncer();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
liveAnnouncer.announce(message, assertiveness, timeout);
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
/**
|
|
42
36
|
* Stops all queued announcements.
|
|
43
37
|
*/
|
|
44
38
|
export function clearAnnouncer(assertiveness: Assertiveness) {
|
|
45
|
-
|
|
39
|
+
if (liveAnnouncer) {
|
|
40
|
+
liveAnnouncer.clear(assertiveness);
|
|
41
|
+
}
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
/**
|
|
49
45
|
* Removes the announcer from the DOM.
|
|
50
46
|
*/
|
|
51
47
|
export function destroyAnnouncer() {
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
node = null;
|
|
48
|
+
if (liveAnnouncer) {
|
|
49
|
+
liveAnnouncer.destroy();
|
|
50
|
+
liveAnnouncer = null;
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
|
|
54
|
+
// LiveAnnouncer is implemented using vanilla DOM, not React. That's because as of React 18
|
|
55
|
+
// ReactDOM.render is deprecated, and the replacement, ReactDOM.createRoot is moved into a
|
|
56
|
+
// subpath import `react-dom/client`. That makes it hard for us to support multiple React versions.
|
|
57
|
+
// As a global API, we can't use portals without introducing a breaking API change. LiveAnnouncer
|
|
58
|
+
// is simple enough to implement without React, so that's what we do here.
|
|
59
|
+
// See this discussion for more details: https://github.com/reactwg/react-18/discussions/125#discussioncomment-2382638
|
|
60
|
+
class LiveAnnouncer {
|
|
61
|
+
node: HTMLElement;
|
|
62
|
+
assertiveLog: HTMLElement;
|
|
63
|
+
politeLog: HTMLElement;
|
|
64
|
+
|
|
65
|
+
constructor() {
|
|
66
|
+
this.node = document.createElement('div');
|
|
67
|
+
this.node.dataset.liveAnnouncer = 'true';
|
|
68
|
+
// copied from VisuallyHidden
|
|
69
|
+
Object.assign(this.node.style, {
|
|
70
|
+
border: 0,
|
|
71
|
+
clip: 'rect(0 0 0 0)',
|
|
72
|
+
clipPath: 'inset(50%)',
|
|
73
|
+
height: 1,
|
|
74
|
+
margin: '0 -1px -1px 0',
|
|
75
|
+
overflow: 'hidden',
|
|
76
|
+
padding: 0,
|
|
77
|
+
position: 'absolute',
|
|
78
|
+
width: 1,
|
|
79
|
+
whiteSpace: 'nowrap'
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
this.assertiveLog = this.createLog('assertive');
|
|
83
|
+
this.node.appendChild(this.assertiveLog);
|
|
84
|
+
|
|
85
|
+
this.politeLog = this.createLog('polite');
|
|
86
|
+
this.node.appendChild(this.politeLog);
|
|
87
|
+
|
|
88
|
+
document.body.prepend(this.node);
|
|
74
89
|
}
|
|
75
|
-
}
|
|
76
90
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
createLog(ariaLive: string) {
|
|
92
|
+
let node = document.createElement('div');
|
|
93
|
+
node.setAttribute('role', 'log');
|
|
94
|
+
node.setAttribute('aria-live', ariaLive);
|
|
95
|
+
node.setAttribute('aria-relevant', 'additions');
|
|
96
|
+
return node;
|
|
97
|
+
}
|
|
80
98
|
|
|
81
|
-
|
|
82
|
-
if (!
|
|
83
|
-
|
|
99
|
+
destroy() {
|
|
100
|
+
if (!this.node) {
|
|
101
|
+
return;
|
|
84
102
|
}
|
|
85
103
|
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
document.body.removeChild(this.node);
|
|
105
|
+
this.node = null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
announce(message: string, assertiveness = 'assertive', timeout = LIVEREGION_TIMEOUT_DELAY) {
|
|
109
|
+
if (!this.node) {
|
|
110
|
+
return;
|
|
88
111
|
}
|
|
89
|
-
};
|
|
90
112
|
|
|
91
|
-
|
|
92
|
-
|
|
113
|
+
let node = document.createElement('div');
|
|
114
|
+
node.textContent = message;
|
|
93
115
|
|
|
94
116
|
if (assertiveness === 'assertive') {
|
|
95
|
-
|
|
117
|
+
this.assertiveLog.appendChild(node);
|
|
96
118
|
} else {
|
|
97
|
-
|
|
119
|
+
this.politeLog.appendChild(node);
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
if (message !== '') {
|
|
101
123
|
setTimeout(() => {
|
|
102
|
-
|
|
103
|
-
setAssertiveMessages(messages => messages.filter(message => message.id !== id));
|
|
104
|
-
} else {
|
|
105
|
-
setPoliteMessages(messages => messages.filter(message => message.id !== id));
|
|
106
|
-
}
|
|
124
|
+
node.remove();
|
|
107
125
|
}, timeout);
|
|
108
126
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
</Fragment>
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
interface MessageBlockProps {
|
|
129
|
-
children: ReactNode,
|
|
130
|
-
'aria-live': Assertiveness
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function MessageBlock({children, 'aria-live': ariaLive}: MessageBlockProps) {
|
|
134
|
-
return (
|
|
135
|
-
<VisuallyHidden
|
|
136
|
-
role="log"
|
|
137
|
-
aria-live={ariaLive}
|
|
138
|
-
aria-relevant="additions">
|
|
139
|
-
{children}
|
|
140
|
-
</VisuallyHidden>
|
|
141
|
-
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
clear(assertiveness: Assertiveness) {
|
|
130
|
+
if (!this.node) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!assertiveness || assertiveness === 'assertive') {
|
|
135
|
+
this.assertiveLog.innerHTML = '';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!assertiveness || assertiveness === 'polite') {
|
|
139
|
+
this.politeLog.innerHTML = '';
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
142
|
}
|