@react-aria/utils
Advanced tools
Comparing version 3.0.0-rc.1 to 3.0.0-rc.2
315
dist/main.js
@@ -1,5 +0,6 @@ | ||
var _babelRuntimeHelpersEsmSlicedToArray = $parcel$interopDefault(require("@babel/runtime/helpers/esm/slicedToArray")); | ||
var _babelRuntimeHelpersSlicedToArray = $parcel$interopDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _temp = require("react"); | ||
var useLayoutEffect = _temp.useLayoutEffect; | ||
var useMemo = _temp.useMemo; | ||
@@ -12,3 +13,3 @@ var useState = _temp.useState; | ||
var _babelRuntimeHelpersEsmToConsumableArray = $parcel$interopDefault(require("@babel/runtime/helpers/esm/toConsumableArray")); | ||
var _babelRuntimeHelpersToConsumableArray = $parcel$interopDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
@@ -27,3 +28,3 @@ function $parcel$interopDefault(a) { | ||
var _useState = useState(defaultId), | ||
_useState2 = _babelRuntimeHelpersEsmSlicedToArray(_useState, 2), | ||
_useState2 = _babelRuntimeHelpersSlicedToArray(_useState, 2), | ||
value = _useState2[0], | ||
@@ -65,2 +66,93 @@ setValue = _useState2[1]; | ||
function useSlotId() { | ||
var _useState3 = useState(useId()), | ||
_useState4 = _babelRuntimeHelpersSlicedToArray(_useState3, 2), | ||
id = _useState4[0], | ||
setId = _useState4[1]; | ||
useLayoutEffect(function () { | ||
var setCurr = $dd2a6808931b40a634ed036e6f4c03b$var$map.get(id); | ||
if (setCurr && !document.getElementById(id)) { | ||
setId(null); | ||
} | ||
}, [id]); | ||
return id; | ||
} | ||
exports.useSlotId = useSlotId; | ||
function $d3cd28c168b10827abf6318f227022b0$var$_createForOfIteratorHelper(o) { | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (o = $d3cd28c168b10827abf6318f227022b0$var$_unsupportedIterableToArray(o))) { | ||
var i = 0; | ||
var F = function F() {}; | ||
return { | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var it, | ||
normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
s: function s() { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
function $d3cd28c168b10827abf6318f227022b0$var$_unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return $d3cd28c168b10827abf6318f227022b0$var$_arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(n); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return $d3cd28c168b10827abf6318f227022b0$var$_arrayLikeToArray(o, minLen); | ||
} | ||
function $d3cd28c168b10827abf6318f227022b0$var$_arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) { | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
/* | ||
@@ -71,2 +163,3 @@ * Copyright 2020 Adobe. All rights reserved. | ||
* 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 | ||
@@ -77,2 +170,4 @@ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
*/ | ||
function chain() { | ||
@@ -84,8 +179,7 @@ for (var _len = arguments.length, callbacks = new Array(_len), _key = 0; _key < _len; _key++) { | ||
return function () { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
var _iterator = $d3cd28c168b10827abf6318f227022b0$var$_createForOfIteratorHelper(callbacks), | ||
_step; | ||
try { | ||
for (var _iterator = callbacks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var callback = _step.value; | ||
@@ -98,14 +192,5 @@ | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
_iterator.e(err); | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
_iterator.f(); | ||
} | ||
@@ -126,2 +211,4 @@ }; | ||
res[_key] = _classnames(a.className, b.className); | ||
} else if (_key === 'UNSAFE_className' && typeof a.UNSAFE_className === 'string' && typeof b.UNSAFE_className === 'string') { | ||
res[_key] = _classnames(a.UNSAFE_className, b.UNSAFE_className); | ||
} else if (_key === 'id' && a.id && b.id) { | ||
@@ -146,2 +233,13 @@ res.id = mergeIds(a.id, b.id); // Override others | ||
/* | ||
* Copyright 2020 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. | ||
*/ | ||
function clamp(value) { | ||
@@ -353,4 +451,4 @@ var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity; | ||
if (labelledBy && label) { | ||
var ids = new Set([].concat(_babelRuntimeHelpersEsmToConsumableArray(labelledBy.trim().split(/\s+/)), [id])); | ||
labelledBy = _babelRuntimeHelpersEsmToConsumableArray(ids).join(' '); | ||
var ids = new Set([].concat(_babelRuntimeHelpersToConsumableArray(labelledBy.trim().split(/\s+/)), [id])); | ||
labelledBy = _babelRuntimeHelpersToConsumableArray(ids).join(' '); | ||
} else if (labelledBy) { | ||
@@ -387,2 +485,177 @@ labelledBy = labelledBy.trim().split(/\s+/).join(' '); | ||
exports.useUpdateEffect = useUpdateEffect; | ||
exports.useUpdateEffect = useUpdateEffect; | ||
function $a5287697384fb579cdf94b55b288b$var$_createForOfIteratorHelper(o) { | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (o = $a5287697384fb579cdf94b55b288b$var$_unsupportedIterableToArray(o))) { | ||
var i = 0; | ||
var F = function F() {}; | ||
return { | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var it, | ||
normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
s: function s() { | ||
it = o[Symbol.iterator](); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
if (!normalCompletion && it.return != null) it.return(); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
} | ||
}; | ||
} | ||
function $a5287697384fb579cdf94b55b288b$var$_unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return $a5287697384fb579cdf94b55b288b$var$_arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(n); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return $a5287697384fb579cdf94b55b288b$var$_arrayLikeToArray(o, minLen); | ||
} | ||
function $a5287697384fb579cdf94b55b288b$var$_arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) { | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
/* | ||
* Copyright 2020 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. | ||
*/ | ||
// This is a polyfill for element.focus({preventScroll: true}); | ||
// Currently necessary for Safari and old Edge: | ||
// https://caniuse.com/#feat=mdn-api_htmlelement_focus_preventscroll_option | ||
// See https://bugs.webkit.org/show_bug.cgi?id=178583 | ||
// | ||
// Heavily based on https://github.com/calvellido/focus-options-polyfill | ||
function focusWithoutScrolling(element) { | ||
if ($a5287697384fb579cdf94b55b288b$var$supportsPreventScroll()) { | ||
element.focus({ | ||
preventScroll: true | ||
}); | ||
} else { | ||
var scrollableElements = $a5287697384fb579cdf94b55b288b$var$getScrollableElements(element); | ||
element.focus(); | ||
$a5287697384fb579cdf94b55b288b$var$restoreScrollPosition(scrollableElements); | ||
} | ||
} | ||
exports.focusWithoutScrolling = focusWithoutScrolling; | ||
var $a5287697384fb579cdf94b55b288b$var$supportsPreventScrollCached = null; | ||
function $a5287697384fb579cdf94b55b288b$var$supportsPreventScroll() { | ||
if ($a5287697384fb579cdf94b55b288b$var$supportsPreventScrollCached == null) { | ||
$a5287697384fb579cdf94b55b288b$var$supportsPreventScrollCached = false; | ||
try { | ||
var focusElem = document.createElement('div'); | ||
focusElem.focus({ | ||
get preventScroll() { | ||
$a5287697384fb579cdf94b55b288b$var$supportsPreventScrollCached = true; | ||
return true; | ||
} | ||
}); | ||
} catch (e) {// Ignore | ||
} | ||
} | ||
return $a5287697384fb579cdf94b55b288b$var$supportsPreventScrollCached; | ||
} | ||
function $a5287697384fb579cdf94b55b288b$var$getScrollableElements(element) { | ||
var parent = element.parentNode; | ||
var scrollableElements = []; | ||
var rootScrollingElement = document.scrollingElement || document.documentElement; | ||
while (parent instanceof HTMLElement && parent !== rootScrollingElement) { | ||
if (parent.offsetHeight < parent.scrollHeight || parent.offsetWidth < parent.scrollWidth) { | ||
scrollableElements.push({ | ||
element: parent, | ||
scrollTop: parent.scrollTop, | ||
scrollLeft: parent.scrollLeft | ||
}); | ||
} | ||
parent = parent.parentNode; | ||
} | ||
if (rootScrollingElement instanceof HTMLElement) { | ||
scrollableElements.push({ | ||
element: rootScrollingElement, | ||
scrollTop: rootScrollingElement.scrollTop, | ||
scrollLeft: rootScrollingElement.scrollLeft | ||
}); | ||
} | ||
return scrollableElements; | ||
} | ||
function $a5287697384fb579cdf94b55b288b$var$restoreScrollPosition(scrollableElements) { | ||
var _iterator = $a5287697384fb579cdf94b55b288b$var$_createForOfIteratorHelper(scrollableElements), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _step.value, | ||
element = _step$value.element, | ||
scrollTop = _step$value.scrollTop, | ||
scrollLeft = _step$value.scrollLeft; | ||
element.scrollTop = scrollTop; | ||
element.scrollLeft = scrollLeft; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { useMemo, useState, useRef, useEffect } from "react"; | ||
import { useLayoutEffect, useMemo, useState, useRef, useEffect } from "react"; | ||
import _classnames from "classnames"; | ||
@@ -35,3 +35,14 @@ let $cd19650f495ff8ac1e00dac56402ca3$var$map = new Map(); | ||
} | ||
export function useSlotId() { | ||
let [id, setId] = useState(useId()); | ||
useLayoutEffect(() => { | ||
let setCurr = $cd19650f495ff8ac1e00dac56402ca3$var$map.get(id); | ||
if (setCurr && !document.getElementById(id)) { | ||
setId(null); | ||
} | ||
}, [id]); | ||
return id; | ||
} | ||
/* | ||
@@ -42,2 +53,3 @@ * Copyright 2020 Adobe. All rights reserved. | ||
* 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 | ||
@@ -66,2 +78,4 @@ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
res[key] = _classnames(a.className, b.className); | ||
} else if (key === 'UNSAFE_className' && typeof a.UNSAFE_className === 'string' && typeof b.UNSAFE_className === 'string') { | ||
res[key] = _classnames(a.UNSAFE_className, b.UNSAFE_className); | ||
} else if (key === 'id' && a.id && b.id) { | ||
@@ -89,2 +103,3 @@ res.id = mergeIds(a.id, b.id); // Override others | ||
* 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 | ||
@@ -104,2 +119,3 @@ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* 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 | ||
@@ -331,2 +347,79 @@ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
}, dependencies); | ||
} | ||
// This is a polyfill for element.focus({preventScroll: true}); | ||
// Currently necessary for Safari and old Edge: | ||
// https://caniuse.com/#feat=mdn-api_htmlelement_focus_preventscroll_option | ||
// See https://bugs.webkit.org/show_bug.cgi?id=178583 | ||
// | ||
// Heavily based on https://github.com/calvellido/focus-options-polyfill | ||
export function focusWithoutScrolling(element) { | ||
if ($ac08b12e470ae7eec1071d5c603$var$supportsPreventScroll()) { | ||
element.focus({ | ||
preventScroll: true | ||
}); | ||
} else { | ||
let scrollableElements = $ac08b12e470ae7eec1071d5c603$var$getScrollableElements(element); | ||
element.focus(); | ||
$ac08b12e470ae7eec1071d5c603$var$restoreScrollPosition(scrollableElements); | ||
} | ||
} | ||
let $ac08b12e470ae7eec1071d5c603$var$supportsPreventScrollCached = null; | ||
function $ac08b12e470ae7eec1071d5c603$var$supportsPreventScroll() { | ||
if ($ac08b12e470ae7eec1071d5c603$var$supportsPreventScrollCached == null) { | ||
$ac08b12e470ae7eec1071d5c603$var$supportsPreventScrollCached = false; | ||
try { | ||
var focusElem = document.createElement('div'); | ||
focusElem.focus({ | ||
get preventScroll() { | ||
$ac08b12e470ae7eec1071d5c603$var$supportsPreventScrollCached = true; | ||
return true; | ||
} | ||
}); | ||
} catch (e) {// Ignore | ||
} | ||
} | ||
return $ac08b12e470ae7eec1071d5c603$var$supportsPreventScrollCached; | ||
} | ||
function $ac08b12e470ae7eec1071d5c603$var$getScrollableElements(element) { | ||
var parent = element.parentNode; | ||
var scrollableElements = []; | ||
var rootScrollingElement = document.scrollingElement || document.documentElement; | ||
while (parent instanceof HTMLElement && parent !== rootScrollingElement) { | ||
if (parent.offsetHeight < parent.scrollHeight || parent.offsetWidth < parent.scrollWidth) { | ||
scrollableElements.push({ | ||
element: parent, | ||
scrollTop: parent.scrollTop, | ||
scrollLeft: parent.scrollLeft | ||
}); | ||
} | ||
parent = parent.parentNode; | ||
} | ||
if (rootScrollingElement instanceof HTMLElement) { | ||
scrollableElements.push({ | ||
element: rootScrollingElement, | ||
scrollTop: rootScrollingElement.scrollTop, | ||
scrollLeft: rootScrollingElement.scrollLeft | ||
}); | ||
} | ||
return scrollableElements; | ||
} | ||
function $ac08b12e470ae7eec1071d5c603$var$restoreScrollPosition(scrollableElements) { | ||
for (let { | ||
element, | ||
scrollTop, | ||
scrollLeft | ||
} of scrollableElements) { | ||
element.scrollTop = scrollTop; | ||
element.scrollLeft = scrollLeft; | ||
} | ||
} |
@@ -1,5 +0,6 @@ | ||
import { AllHTMLAttributes, MutableRefObject, EffectCallback } from "react"; | ||
import { DOMProps } from "@react-types/shared"; | ||
import { HTMLAttributes, MutableRefObject, EffectCallback } from "react"; | ||
import { Orientation, DOMProps } from "@react-types/shared"; | ||
export function useId(defaultId?: string): string; | ||
export function mergeIds(a: string, b: string): string; | ||
export function useSlotId(): string; | ||
export function chain(...callbacks: any[]): (...args: any[]) => void; | ||
@@ -15,3 +16,3 @@ interface Props { | ||
reverse?: boolean; | ||
orientation?: 'horizontal' | 'vertical'; | ||
orientation?: Orientation; | ||
onHover?: (hovered: boolean) => void; | ||
@@ -26,6 +27,7 @@ onDrag?: (dragging: boolean) => void; | ||
} | ||
export function useDrag1D(props: UseDrag1DProps): AllHTMLAttributes<HTMLElement>; | ||
export function useDrag1D(props: UseDrag1DProps): HTMLAttributes<HTMLElement>; | ||
export function useLabels(props: DOMProps, defaultLabel?: string): DOMProps; | ||
export function useUpdateEffect(effect: EffectCallback, dependencies: any[]): void; | ||
export function focusWithoutScrolling(element: HTMLElement): void; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "@react-aria/utils", | ||
"version": "3.0.0-rc.1", | ||
"version": "3.0.0-rc.2", | ||
"description": "Spectrum UI components in React", | ||
@@ -20,3 +20,3 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-types/shared": "^3.0.0-rc.1", | ||
"@react-types/shared": "^3.0.0-rc.2", | ||
"classnames": "^2.2.5" | ||
@@ -30,3 +30,3 @@ }, | ||
}, | ||
"gitHead": "5a9784f0bb6c25af7422215efb31ef72caeb9600" | ||
"gitHead": "207e6ee9076905c96638a7f81a367758872e1410" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47122
7
916