@primer/live-region-element
Advanced tools
Comparing version
@@ -357,15 +357,4 @@ const Ordering = { | ||
function announce(message, options = {}) { | ||
const liveRegion2 = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion2.announce(message, options); | ||
} | ||
function announceFromElement(element, options = {}) { | ||
const liveRegion2 = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion2.announceFromElement(element, options); | ||
} | ||
let liveRegion = null; | ||
function findOrCreateLiveRegion(from, appendTo) { | ||
if (liveRegion !== null && liveRegion.isConnected) { | ||
return liveRegion; | ||
} | ||
let liveRegion = null; | ||
liveRegion = from ? getClosestLiveRegion(from) : null; | ||
@@ -375,3 +364,10 @@ if (liveRegion !== null) { | ||
} | ||
liveRegion = document.querySelector("live-region"); | ||
let container = document.body; | ||
if (from) { | ||
const dialog = from.closest("dialog"); | ||
if (dialog) { | ||
container = dialog; | ||
} | ||
} | ||
liveRegion = container.querySelector("live-region"); | ||
if (liveRegion !== null) { | ||
@@ -384,3 +380,3 @@ return liveRegion; | ||
} else { | ||
document.body.appendChild(liveRegion); | ||
container.appendChild(liveRegion); | ||
} | ||
@@ -390,4 +386,8 @@ return liveRegion; | ||
function getClosestLiveRegion(from) { | ||
const dialog = from.closest("dialog"); | ||
let current = from; | ||
while (current = current.parentElement) { | ||
if (dialog && !dialog.contains(current)) { | ||
break; | ||
} | ||
for (const child of current.childNodes) { | ||
@@ -402,2 +402,11 @@ if (child instanceof LiveRegionElement) { | ||
function announce(message, options = {}) { | ||
const liveRegion = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion.announce(message, options); | ||
} | ||
function announceFromElement(element, options = {}) { | ||
const liveRegion = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion.announceFromElement(element, options); | ||
} | ||
export { LiveRegionElement, announce, announceFromElement, templateContent }; |
@@ -359,15 +359,4 @@ import { HTMLElement, customElements } from '@lit-labs/ssr-dom-shim'; | ||
function announce(message, options = {}) { | ||
const liveRegion2 = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion2.announce(message, options); | ||
} | ||
function announceFromElement(element, options = {}) { | ||
const liveRegion2 = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion2.announceFromElement(element, options); | ||
} | ||
let liveRegion = null; | ||
function findOrCreateLiveRegion(from, appendTo) { | ||
if (liveRegion !== null && liveRegion.isConnected) { | ||
return liveRegion; | ||
} | ||
let liveRegion = null; | ||
liveRegion = from ? getClosestLiveRegion(from) : null; | ||
@@ -377,3 +366,10 @@ if (liveRegion !== null) { | ||
} | ||
liveRegion = document.querySelector("live-region"); | ||
let container = document.body; | ||
if (from) { | ||
const dialog = from.closest("dialog"); | ||
if (dialog) { | ||
container = dialog; | ||
} | ||
} | ||
liveRegion = container.querySelector("live-region"); | ||
if (liveRegion !== null) { | ||
@@ -386,3 +382,3 @@ return liveRegion; | ||
} else { | ||
document.body.appendChild(liveRegion); | ||
container.appendChild(liveRegion); | ||
} | ||
@@ -392,4 +388,8 @@ return liveRegion; | ||
function getClosestLiveRegion(from) { | ||
const dialog = from.closest("dialog"); | ||
let current = from; | ||
while (current = current.parentElement) { | ||
if (dialog && !dialog.contains(current)) { | ||
break; | ||
} | ||
for (const child of current.childNodes) { | ||
@@ -404,2 +404,11 @@ if (child instanceof LiveRegionElement) { | ||
function announce(message, options = {}) { | ||
const liveRegion = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion.announce(message, options); | ||
} | ||
function announceFromElement(element, options = {}) { | ||
const liveRegion = findOrCreateLiveRegion(options.from, options.appendTo); | ||
return liveRegion.announceFromElement(element, options); | ||
} | ||
export { LiveRegionElement, announce, announceFromElement, templateContent }; |
{ | ||
"name": "@primer/live-region-element", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/esm/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
63056
1.91%20
11.11%1723
2.07%0
-100%