@react-aria/landmark
Advanced tools
Comparing version 3.0.0-nightly.3599 to 3.0.0-nightly.3600
@@ -0,1 +1,2 @@ | ||
require("@swc/helpers/lib/_define_property.js"); | ||
var $8Ore6$react = require("react"); | ||
@@ -9,2 +10,23 @@ var $8Ore6$reactariautils = require("@react-aria/utils"); | ||
$parcel$export(module.exports, "useLandmark", () => $202c109aedff6705$export$4cc632584fd87fae); | ||
/* | ||
* Copyright 2022 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ /* | ||
* Copyright 2022 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
@@ -18,9 +40,9 @@ | ||
setup() { | ||
document.addEventListener('keydown', this.f6Handler, { | ||
document.addEventListener("keydown", this.f6Handler, { | ||
capture: true | ||
}); | ||
document.addEventListener('focusin', this.focusinHandler, { | ||
document.addEventListener("focusin", this.focusinHandler, { | ||
capture: true | ||
}); | ||
document.addEventListener('focusout', this.focusoutHandler, { | ||
document.addEventListener("focusout", this.focusoutHandler, { | ||
capture: true | ||
@@ -31,9 +53,9 @@ }); | ||
teardown() { | ||
document.removeEventListener('keydown', this.f6Handler, { | ||
document.removeEventListener("keydown", this.f6Handler, { | ||
capture: true | ||
}); | ||
document.removeEventListener('focusin', this.focusinHandler, { | ||
document.removeEventListener("focusin", this.focusinHandler, { | ||
capture: true | ||
}); | ||
document.removeEventListener('focusout', this.focusoutHandler, { | ||
document.removeEventListener("focusout", this.focusoutHandler, { | ||
capture: true | ||
@@ -45,4 +67,3 @@ }); | ||
var ref; | ||
(ref = this.landmarks.find((l)=>l.ref.current === landmark | ||
)) === null || ref === void 0 ? void 0 : ref.focus(); | ||
(ref = this.landmarks.find((l)=>l.ref.current === landmark)) === null || ref === void 0 ? void 0 : ref.focus(); | ||
} | ||
@@ -52,4 +73,3 @@ /** | ||
*/ getLandmarksByRole(role) { | ||
return new Set(this.landmarks.filter((l)=>l.role === role | ||
)); | ||
return new Set(this.landmarks.filter((l)=>l.role === role)); | ||
} | ||
@@ -59,11 +79,8 @@ /** | ||
*/ getLandmarkByRole(role) { | ||
return this.landmarks.find((l)=>l.role === role | ||
); | ||
return this.landmarks.find((l)=>l.role === role); | ||
} | ||
addLandmark(newLandmark) { | ||
if (!this.isListening) this.setup(); | ||
if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref | ||
)) return; | ||
if (this.landmarks.filter((landmark)=>landmark.role === 'main' | ||
).length > 1) console.error('Page can contain no more than one landmark with the role "main".'); | ||
if (this.landmarks.find((landmark)=>landmark.ref === newLandmark.ref)) return; | ||
if (this.landmarks.filter((landmark)=>landmark.role === "main").length > 1) console.error('Page can contain no more than one landmark with the role "main".'); | ||
if (this.landmarks.length === 0) { | ||
@@ -89,4 +106,3 @@ this.landmarks = [ | ||
updateLandmark(landmark) { | ||
let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref | ||
); | ||
let index = this.landmarks.findIndex((l)=>l.ref === landmark.ref); | ||
if (index >= 0) { | ||
@@ -101,4 +117,3 @@ this.landmarks[index] = { | ||
removeLandmark(ref) { | ||
this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref | ||
); | ||
this.landmarks = this.landmarks.filter((landmark)=>landmark.ref !== ref); | ||
if (this.landmarks.length === 0) this.teardown(); | ||
@@ -116,19 +131,13 @@ } | ||
...landmarksWithRole | ||
].filter((landmark)=>!landmark.label | ||
); | ||
if (duplicatesWithoutLabel.length > 0) console.warn(`Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `, duplicatesWithoutLabel.map((landmark)=>landmark.ref.current | ||
)); | ||
].filter((landmark)=>!landmark.label); | ||
if (duplicatesWithoutLabel.length > 0) console.warn(`Page contains more than one landmark with the '${role}' role. If two or more landmarks on a page share the same role, all must be labeled with an aria-label or aria-labelledby attribute: `, duplicatesWithoutLabel.map((landmark)=>landmark.ref.current)); | ||
else { | ||
let labels = [ | ||
...landmarksWithRole | ||
].map((landmark)=>landmark.label | ||
); | ||
let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index | ||
); | ||
].map((landmark)=>landmark.label); | ||
let duplicateLabels = labels.filter((item, index)=>labels.indexOf(item) !== index); | ||
duplicateLabels.forEach((label)=>{ | ||
console.warn(`Page contains more than one landmark with the '${role}' role and '${label}' label. If two or more landmarks on a page share the same role, they must have unique labels: `, [ | ||
...landmarksWithRole | ||
].filter((landmark)=>landmark.label === label | ||
).map((landmark)=>landmark.ref.current | ||
)); | ||
].filter((landmark)=>landmark.label === label).map((landmark)=>landmark.ref.current)); | ||
}); | ||
@@ -145,4 +154,3 @@ } | ||
l | ||
] | ||
)); | ||
])); | ||
let currentElement = element; | ||
@@ -161,4 +169,3 @@ while(!landmarkMap.has(currentElement) && currentElement !== document.body)currentElement = currentElement.parentElement; | ||
let nextLandmarkIndex = backward ? -1 : 0; | ||
if (currentLandmark) nextLandmarkIndex = this.landmarks.findIndex((landmark)=>landmark === currentLandmark | ||
) + (backward ? -1 : 1); | ||
if (currentLandmark) nextLandmarkIndex = this.landmarks.findIndex((landmark)=>landmark === currentLandmark) + (backward ? -1 : 1); | ||
// Wrap if necessary | ||
@@ -174,3 +181,3 @@ if (nextLandmarkIndex < 0) nextLandmarkIndex = this.landmarks.length - 1; | ||
*/ f6Handler(e) { | ||
if (e.key === 'F6') { | ||
if (e.key === "F6") { | ||
e.preventDefault(); | ||
@@ -186,3 +193,3 @@ e.stopPropagation(); | ||
if (e.altKey) { | ||
let main = this.getLandmarkByRole('main'); | ||
let main = this.getLandmarkByRole("main"); | ||
if (main && document.contains(main.ref.current)) this.focusLandmark(main.ref.current); | ||
@@ -231,4 +238,4 @@ return; | ||
constructor(){ | ||
this.landmarks = []; | ||
this.isListening = false; | ||
(0, $202c109aedff6705$import$d76420afe0f7f8c4$2e2bcd8739ae039)(this, "landmarks", []); | ||
(0, $202c109aedff6705$import$d76420afe0f7f8c4$2e2bcd8739ae039)(this, "isListening", false); | ||
this.f6Handler = this.f6Handler.bind(this); | ||
@@ -240,7 +247,7 @@ this.focusinHandler = this.focusinHandler.bind(this); | ||
function $202c109aedff6705$export$4cc632584fd87fae(props, ref) { | ||
const { role: role , 'aria-label': ariaLabel , 'aria-labelledby': ariaLabelledby } = props; | ||
const { role: role , "aria-label": ariaLabel , "aria-labelledby": ariaLabelledby } = props; | ||
let manager = $202c109aedff6705$var$LandmarkManager.getInstance(); | ||
let label = ariaLabel || ariaLabelledby; | ||
let [isLandmarkFocused, setIsLandmarkFocused] = $8Ore6$react.useState(false); | ||
let focus = $8Ore6$react.useCallback(()=>{ | ||
let [isLandmarkFocused, setIsLandmarkFocused] = (0, $8Ore6$react.useState)(false); | ||
let focus = (0, $8Ore6$react.useCallback)(()=>{ | ||
setIsLandmarkFocused(true); | ||
@@ -250,3 +257,3 @@ }, [ | ||
]); | ||
let blur = $8Ore6$react.useCallback(()=>{ | ||
let blur = (0, $8Ore6$react.useCallback)(()=>{ | ||
setIsLandmarkFocused(false); | ||
@@ -256,3 +263,3 @@ }, [ | ||
]); | ||
$8Ore6$reactariautils.useLayoutEffect(()=>{ | ||
(0, $8Ore6$reactariautils.useLayoutEffect)(()=>{ | ||
manager.addLandmark({ | ||
@@ -270,3 +277,3 @@ ref: ref, | ||
}, []); | ||
$8Ore6$reactariautils.useLayoutEffect(()=>{ | ||
(0, $8Ore6$reactariautils.useLayoutEffect)(()=>{ | ||
manager.updateLandmark({ | ||
@@ -285,3 +292,3 @@ ref: ref, | ||
]); | ||
$8Ore6$react.useEffect(()=>{ | ||
(0, $8Ore6$react.useEffect)(()=>{ | ||
if (isLandmarkFocused) ref.current.focus(); | ||
@@ -288,0 +295,0 @@ }, [ |
{ | ||
"name": "@react-aria/landmark", | ||
"version": "3.0.0-nightly.3599+b35d5c02f", | ||
"version": "3.0.0-nightly.3600+bfce84fee", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,6 +25,6 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/focus": "3.0.0-nightly.1899+b35d5c02f", | ||
"@react-aria/utils": "3.0.0-nightly.1899+b35d5c02f", | ||
"@react-types/shared": "3.0.0-nightly.1899+b35d5c02f" | ||
"@react-aria/focus": "3.0.0-nightly.1900+bfce84fee", | ||
"@react-aria/utils": "3.0.0-nightly.1900+bfce84fee", | ||
"@react-types/shared": "3.0.0-nightly.1900+bfce84fee", | ||
"@swc/helpers": "^0.4.14" | ||
}, | ||
@@ -37,3 +37,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "b35d5c02fe900badccd0cf1a8f23bb593419f238" | ||
"gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
883
90946
+ Added@swc/helpers@^0.4.14
+ Added@swc/helpers@0.4.37(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@babel/runtime@^7.6.2
- Removed@babel/runtime@7.26.7(transitive)
- Removedregenerator-runtime@0.14.1(transitive)