cleanup
This commit is contained in:
@@ -80,14 +80,15 @@ const BreadcrumbTrail = ({
|
||||
};
|
||||
|
||||
const scheduleMeasure = () => {
|
||||
if (typeof window === 'undefined' || typeof window.requestAnimationFrame !== 'function') {
|
||||
const raf = window.requestAnimationFrame;
|
||||
if (!raf) {
|
||||
measure();
|
||||
return;
|
||||
}
|
||||
if (measureRafRef.current) {
|
||||
cancelAnimationFrame(measureRafRef.current);
|
||||
}
|
||||
measureRafRef.current = window.requestAnimationFrame(() => {
|
||||
measureRafRef.current = raf(() => {
|
||||
measureRafRef.current = null;
|
||||
measure();
|
||||
});
|
||||
@@ -95,7 +96,7 @@ const BreadcrumbTrail = ({
|
||||
|
||||
scheduleMeasure();
|
||||
|
||||
if (typeof ResizeObserver === 'undefined') {
|
||||
if (!('ResizeObserver' in window)) {
|
||||
return () => {
|
||||
if (measureRafRef.current) {
|
||||
cancelAnimationFrame(measureRafRef.current);
|
||||
@@ -364,7 +365,6 @@ const BreadcrumbTrail = ({
|
||||
{ellipsisMenuOpen
|
||||
&& hasHiddenEntries
|
||||
&& ellipsisMenuStyle
|
||||
&& typeof document !== 'undefined'
|
||||
? createPortal(
|
||||
<div
|
||||
className="menu menu--floating"
|
||||
|
||||
@@ -6,20 +6,21 @@ const normalizeOption = (option, index) => {
|
||||
if (option == null) {
|
||||
return null;
|
||||
}
|
||||
if (typeof option === 'string') {
|
||||
if (option && typeof option === 'object') {
|
||||
const label = option.label ?? option.name;
|
||||
if (label == null) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
id: option,
|
||||
label: option,
|
||||
id: option.id ?? label,
|
||||
label: String(label),
|
||||
original: option,
|
||||
index,
|
||||
};
|
||||
}
|
||||
const label = option.label ?? option.name;
|
||||
if (!label) {
|
||||
return null;
|
||||
}
|
||||
const label = String(option);
|
||||
return {
|
||||
id: option.id ?? label,
|
||||
id: label,
|
||||
label,
|
||||
original: option,
|
||||
index,
|
||||
@@ -90,7 +91,7 @@ const QuickAddMenu = ({
|
||||
() =>
|
||||
options
|
||||
.map((option, index) => normalizeOption(option, index))
|
||||
.filter((option) => option && typeof option.label === 'string'),
|
||||
.filter(Boolean),
|
||||
[options],
|
||||
);
|
||||
|
||||
|
||||
@@ -3,15 +3,7 @@ import { clamp } from '../utils/math';
|
||||
|
||||
const DEFAULT_VIEWPORT_MARGIN = 8;
|
||||
|
||||
const resolveViewportWidth = () => {
|
||||
if (typeof window !== 'undefined' && typeof window.innerWidth === 'number') {
|
||||
return window.innerWidth;
|
||||
}
|
||||
if (typeof document !== 'undefined' && document.documentElement) {
|
||||
return document.documentElement.clientWidth;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
const resolveViewportWidth = () => window.innerWidth || document.documentElement.clientWidth || 0;
|
||||
|
||||
const computeWidth = (anchorWidth, minWidth, matchAnchorWidth) => {
|
||||
if (matchAnchorWidth) {
|
||||
@@ -29,7 +21,7 @@ const formatStyle = (metrics) => {
|
||||
top: metrics.top,
|
||||
left: metrics.left,
|
||||
};
|
||||
if (typeof metrics.minWidth === 'number') {
|
||||
if (Number.isFinite(metrics.minWidth)) {
|
||||
style['--floating-min-width'] = `${Math.max(metrics.minWidth, 0)}px`;
|
||||
}
|
||||
if (metrics.width) {
|
||||
@@ -59,7 +51,7 @@ const useFloatingMenu = ({
|
||||
|
||||
const updatePosition = useCallback(() => {
|
||||
const anchor = anchorRef?.current;
|
||||
if (!anchor || typeof window === 'undefined') {
|
||||
if (!anchor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,7 +101,7 @@ const useFloatingMenu = ({
|
||||
}
|
||||
|
||||
const viewportWidth = resolveViewportWidth();
|
||||
const viewportHeight = typeof window !== 'undefined' ? window.innerHeight : 0;
|
||||
const viewportHeight = window.innerHeight || 0;
|
||||
const safeMargin = viewportMargin ?? DEFAULT_VIEWPORT_MARGIN;
|
||||
const menuHeight = menu?.offsetHeight ?? 0;
|
||||
|
||||
@@ -200,8 +192,9 @@ const useFloatingMenu = ({
|
||||
}
|
||||
|
||||
let ignoreFocusEvents = true;
|
||||
const rafId = typeof window !== 'undefined'
|
||||
? window.requestAnimationFrame(() => {
|
||||
const raf = window.requestAnimationFrame;
|
||||
const rafId = raf
|
||||
? raf(() => {
|
||||
ignoreFocusEvents = false;
|
||||
})
|
||||
: null;
|
||||
|
||||
Reference in New Issue
Block a user