| @@ -1,4 +1,5 @@ | ||
| 1 | +(function() { | |
| 1 | 2 | "use strict"; |
| 2 | 3 | var wp; |
| 3 | 4 | (wp ||= {}).compose = (() => { |
| 4 | 5 | var __create = Object.create; |
| @@ -1156,9 +1157,9 @@ | ||
| 1156 | 1157 | ); |
| 1157 | 1158 | } |
| 1158 | 1159 | render() { |
| 1159 | 1160 | return ( |
| 1160 | - // @ts-ignore | |
| 1161 | + // @ts-expect-error `LibraryManagedAttributes` cannot see the injected timeout props. | |
| 1161 | 1162 | /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( |
| 1162 | 1163 | OriginalComponent, |
| 1163 | 1164 | { |
| 1164 | 1165 | ...this.props, |
| @@ -1228,16 +1229,10 @@ | ||
| 1228 | 1229 | if (key !== "Tab") { |
| 1229 | 1230 | return; |
| 1230 | 1231 | } |
| 1231 | 1232 | const action = shiftKey ? "findPrevious" : "findNext"; |
| 1232 | - const nextElement = import_dom.focus.tabbable[action]( | |
| 1233 | - /** @type {HTMLElement} */ | |
| 1234 | - target | |
| 1235 | - ) || null; | |
| 1236 | - if ( | |
| 1237 | - /** @type {HTMLElement} */ | |
| 1238 | - target.contains(nextElement) | |
| 1239 | - ) { | |
| 1233 | + const nextElement = import_dom.focus.tabbable[action](target) || null; | |
| 1234 | + if (target.contains(nextElement)) { | |
| 1240 | 1235 | event.preventDefault(); |
| 1241 | 1236 | nextElement?.focus(); |
| 1242 | 1237 | return; |
| 1243 | 1238 | } |
| @@ -1449,10 +1444,12 @@ | ||
| 1449 | 1444 | var import_element10 = __toESM(require_element(), 1); |
| 1450 | 1445 | var origin = null; |
| 1451 | 1446 | function useFocusReturn(onFocusReturn) { |
| 1452 | 1447 | const ref = (0, import_element10.useRef)(null); |
| 1453 | - const focusedBeforeMount = (0, import_element10.useRef)(null); | |
| 1454 | - const onFocusReturnRef = (0, import_element10.useRef)(onFocusReturn); | |
| 1448 | + const focusedBeforeMountRef = (0, import_element10.useRef)(null); | |
| 1449 | + const onFocusReturnRef = (0, import_element10.useRef)( | |
| 1450 | + onFocusReturn | |
| 1451 | + ); | |
| 1455 | 1452 | (0, import_element10.useEffect)(() => { |
| 1456 | 1453 | onFocusReturnRef.current = onFocusReturn; |
| 1457 | 1454 | }, [onFocusReturn]); |
| 1458 | 1455 | return (0, import_element10.useCallback)((node) => { |
| @@ -1457,25 +1454,26 @@ | ||
| 1457 | 1454 | }, [onFocusReturn]); |
| 1458 | 1455 | return (0, import_element10.useCallback)((node) => { |
| 1459 | 1456 | if (node) { |
| 1460 | 1457 | ref.current = node; |
| 1461 | - if (focusedBeforeMount.current) { | |
| 1458 | + if (focusedBeforeMountRef.current) { | |
| 1462 | 1459 | return; |
| 1463 | 1460 | } |
| 1464 | 1461 | const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument; |
| 1465 | - focusedBeforeMount.current = activeDocument?.activeElement ?? null; | |
| 1466 | - } else if (focusedBeforeMount.current) { | |
| 1462 | + focusedBeforeMountRef.current = activeDocument?.activeElement ?? null; | |
| 1463 | + } else if (focusedBeforeMountRef.current) { | |
| 1467 | 1464 | const isFocused = ref.current?.contains( |
| 1468 | - ref.current?.ownerDocument.activeElement | |
| 1465 | + ref.current?.ownerDocument.activeElement ?? null | |
| 1469 | 1466 | ); |
| 1470 | 1467 | if (ref.current?.isConnected && !isFocused) { |
| 1471 | - origin ??= focusedBeforeMount.current; | |
| 1468 | + origin ??= focusedBeforeMountRef.current; | |
| 1472 | 1469 | return; |
| 1473 | 1470 | } |
| 1474 | 1471 | if (onFocusReturnRef.current) { |
| 1475 | 1472 | onFocusReturnRef.current(); |
| 1476 | 1473 | } else { |
| 1477 | - (!focusedBeforeMount.current.isConnected ? origin : focusedBeforeMount.current)?.focus(); | |
| 1474 | + const elementToFocus = !focusedBeforeMountRef.current.isConnected ? origin : focusedBeforeMountRef.current; | |
| 1475 | + elementToFocus?.focus(); | |
| 1478 | 1476 | } |
| 1479 | 1477 | origin = null; |
| 1480 | 1478 | } |
| 1481 | 1479 | }, []); |
| @@ -1534,8 +1532,9 @@ | ||
| 1534 | 1532 | ); |
| 1535 | 1533 | if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) { |
| 1536 | 1534 | return; |
| 1537 | 1535 | } |
| 1536 | + clearTimeout(blurCheckTimeoutIdRef.current); | |
| 1538 | 1537 | blurCheckTimeoutIdRef.current = setTimeout(() => { |
| 1539 | 1538 | if (!document.hasFocus()) { |
| 1540 | 1539 | event.preventDefault(); |
| 1541 | 1540 | return; |
| @@ -1576,42 +1575,36 @@ | ||
| 1576 | 1575 | } |
| 1577 | 1576 | } |
| 1578 | 1577 | function useMergeRefs(refs) { |
| 1579 | 1578 | const elementRef = (0, import_element12.useRef)(null); |
| 1580 | - const isAttachedRef = (0, import_element12.useRef)(false); | |
| 1581 | - const didElementChangeRef = (0, import_element12.useRef)(false); | |
| 1582 | - const previousRefsRef = (0, import_element12.useRef)([]); | |
| 1579 | + const attachedRefsRef = (0, import_element12.useRef)([]); | |
| 1583 | 1580 | const currentRefsRef = (0, import_element12.useRef)(refs); |
| 1584 | 1581 | const cleanupsRef = (0, import_element12.useRef)([]); |
| 1585 | 1582 | currentRefsRef.current = refs; |
| 1586 | 1583 | (0, import_element12.useLayoutEffect)(() => { |
| 1587 | - if (didElementChangeRef.current === false && isAttachedRef.current === true) { | |
| 1588 | - refs.forEach((ref, index) => { | |
| 1589 | - const previousRef = previousRefsRef.current[index]; | |
| 1590 | - if (ref !== previousRef) { | |
| 1591 | - detachRef(previousRef, index, cleanupsRef.current); | |
| 1592 | - cleanupsRef.current[index] = assignRef( | |
| 1593 | - ref, | |
| 1594 | - elementRef.current | |
| 1595 | - ); | |
| 1596 | - } | |
| 1597 | - }); | |
| 1584 | + const element = elementRef.current; | |
| 1585 | + if (element === null) { | |
| 1586 | + return; | |
| 1598 | 1587 | } |
| 1599 | - previousRefsRef.current = refs; | |
| 1588 | + refs.forEach((ref, index) => { | |
| 1589 | + const attachedRef = attachedRefsRef.current[index]; | |
| 1590 | + if (ref !== attachedRef) { | |
| 1591 | + detachRef(attachedRef, index, cleanupsRef.current); | |
| 1592 | + cleanupsRef.current[index] = assignRef(ref, element); | |
| 1593 | + } | |
| 1594 | + }); | |
| 1595 | + attachedRefsRef.current = refs; | |
| 1600 | 1596 | }, refs); |
| 1601 | - (0, import_element12.useLayoutEffect)(() => { | |
| 1602 | - didElementChangeRef.current = false; | |
| 1603 | - }); | |
| 1604 | 1597 | return (0, import_element12.useCallback)((value) => { |
| 1605 | 1598 | elementRef.current = value; |
| 1606 | - didElementChangeRef.current = true; | |
| 1607 | - isAttachedRef.current = value !== null; | |
| 1608 | 1599 | if (value === null) { |
| 1609 | - previousRefsRef.current.forEach((ref, index) => { | |
| 1600 | + attachedRefsRef.current.forEach((ref, index) => { | |
| 1610 | 1601 | detachRef(ref, index, cleanupsRef.current); |
| 1611 | 1602 | }); |
| 1603 | + attachedRefsRef.current = []; | |
| 1612 | 1604 | } else { |
| 1613 | - currentRefsRef.current.forEach((ref, index) => { | |
| 1605 | + attachedRefsRef.current = currentRefsRef.current; | |
| 1606 | + attachedRefsRef.current.forEach((ref, index) => { | |
| 1614 | 1607 | cleanupsRef.current[index] = assignRef(ref, value); |
| 1615 | 1608 | }); |
| 1616 | 1609 | } |
| 1617 | 1610 | }, []); |
| @@ -1729,9 +1722,13 @@ | ||
| 1729 | 1722 | var useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_element15.useLayoutEffect : import_element15.useEffect; |
| 1730 | 1723 | var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect; |
| 1731 | 1724 | |
| 1732 | 1725 | // packages/compose/build-module/hooks/use-dragging/index.mjs |
| 1733 | - function useDragging({ onDragStart, onDragMove, onDragEnd }) { | |
| 1726 | + function useDragging({ | |
| 1727 | + onDragStart, | |
| 1728 | + onDragMove, | |
| 1729 | + onDragEnd | |
| 1730 | + }) { | |
| 1734 | 1731 | const [isDragging, setIsDragging] = (0, import_element16.useState)(false); |
| 1735 | 1732 | const eventsRef = (0, import_element16.useRef)({ |
| 1736 | 1733 | onDragStart, |
| 1737 | 1734 | onDragMove, |
| @@ -1741,28 +1738,29 @@ | ||
| 1741 | 1738 | eventsRef.current.onDragStart = onDragStart; |
| 1742 | 1739 | eventsRef.current.onDragMove = onDragMove; |
| 1743 | 1740 | eventsRef.current.onDragEnd = onDragEnd; |
| 1744 | 1741 | }, [onDragStart, onDragMove, onDragEnd]); |
| 1745 | - const onMouseMove = (0, import_element16.useCallback)( | |
| 1746 | - (event) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), | |
| 1747 | - [] | |
| 1742 | + const onMouseMove = (0, import_element16.useCallback)((event) => { | |
| 1743 | + eventsRef.current.onDragMove?.(event); | |
| 1744 | + }, []); | |
| 1745 | + const endDrag = (0, import_element16.useCallback)( | |
| 1746 | + function endDrag2(event) { | |
| 1747 | + eventsRef.current.onDragEnd?.(event); | |
| 1748 | + document.removeEventListener("mousemove", onMouseMove); | |
| 1749 | + document.removeEventListener("mouseup", endDrag2); | |
| 1750 | + setIsDragging(false); | |
| 1751 | + }, | |
| 1752 | + [onMouseMove] | |
| 1748 | 1753 | ); |
| 1749 | - const endDrag = (0, import_element16.useCallback)((event) => { | |
| 1750 | - if (eventsRef.current.onDragEnd) { | |
| 1751 | - eventsRef.current.onDragEnd(event); | |
| 1752 | - } | |
| 1753 | - document.removeEventListener("mousemove", onMouseMove); | |
| 1754 | - document.removeEventListener("mouseup", endDrag); | |
| 1755 | - setIsDragging(false); | |
| 1756 | - }, []); | |
| 1757 | - const startDrag = (0, import_element16.useCallback)((event) => { | |
| 1758 | - if (eventsRef.current.onDragStart) { | |
| 1759 | - eventsRef.current.onDragStart(event); | |
| 1760 | - } | |
| 1761 | - document.addEventListener("mousemove", onMouseMove); | |
| 1762 | - document.addEventListener("mouseup", endDrag); | |
| 1763 | - setIsDragging(true); | |
| 1764 | - }, []); | |
| 1754 | + const startDrag = (0, import_element16.useCallback)( | |
| 1755 | + (event) => { | |
| 1756 | + eventsRef.current.onDragStart?.(event); | |
| 1757 | + document.addEventListener("mousemove", onMouseMove); | |
| 1758 | + document.addEventListener("mouseup", endDrag); | |
| 1759 | + setIsDragging(true); | |
| 1760 | + }, | |
| 1761 | + [onMouseMove, endDrag] | |
| 1762 | + ); | |
| 1765 | 1763 | (0, import_element16.useEffect)(() => { |
| 1766 | 1764 | return () => { |
| 1767 | 1765 | if (isDragging) { |
| 1768 | 1766 | document.removeEventListener("mousemove", onMouseMove); |
| @@ -1768,9 +1766,9 @@ | ||
| 1768 | 1766 | document.removeEventListener("mousemove", onMouseMove); |
| 1769 | 1767 | document.removeEventListener("mouseup", endDrag); |
| 1770 | 1768 | } |
| 1771 | 1769 | }; |
| 1772 | - }, [isDragging]); | |
| 1770 | + }, [isDragging, onMouseMove, endDrag]); | |
| 1773 | 1771 | return { |
| 1774 | 1772 | startDrag, |
| 1775 | 1773 | endDrag, |
| 1776 | 1774 | isDragging |
| @@ -1817,9 +1815,8 @@ | ||
| 1817 | 1815 | function useKeyboardShortcut(shortcuts, callback, { |
| 1818 | 1816 | bindGlobal = false, |
| 1819 | 1817 | eventName = "keydown", |
| 1820 | 1818 | isDisabled = false, |
| 1821 | - // This is important for performance considerations. | |
| 1822 | 1819 | target |
| 1823 | 1820 | } = {}) { |
| 1824 | 1821 | const currentCallbackRef = (0, import_element17.useRef)(callback); |
| 1825 | 1822 | (0, import_element17.useEffect)(() => { |
| @@ -1833,10 +1830,8 @@ | ||
| 1833 | 1830 | target && target.current ? target.current : ( |
| 1834 | 1831 | // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`. |
| 1835 | 1832 | // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's |
| 1836 | 1833 | // necessary to maintain the existing behavior. |
| 1837 | - /** @type {Element} */ | |
| 1838 | - /** @type {unknown} */ | |
| 1839 | 1834 | document |
| 1840 | 1835 | ) |
| 1841 | 1836 | ); |
| 1842 | 1837 | const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts]; |
| @@ -2033,16 +2028,13 @@ | ||
| 2033 | 2028 | var OPERATOR_EVALUATORS = { |
| 2034 | 2029 | ">=": (breakpointValue, width) => width >= breakpointValue, |
| 2035 | 2030 | "<": (breakpointValue, width) => width < breakpointValue |
| 2036 | 2031 | }; |
| 2037 | - var ViewportMatchWidthContext = (0, import_element21.createContext)( | |
| 2038 | - /** @type {null | number} */ | |
| 2039 | - null | |
| 2040 | - ); | |
| 2032 | + var ViewportMatchWidthContext = (0, import_element21.createContext)(null); | |
| 2041 | 2033 | ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext"; |
| 2042 | 2034 | var useViewportMatch = (breakpoint, operator = ">=", view = typeof window !== "undefined" ? window : void 0) => { |
| 2043 | 2035 | const simulatedWidth = (0, import_element21.useContext)(ViewportMatchWidthContext); |
| 2044 | - const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`; | |
| 2036 | + const mediaQuery = !simulatedWidth && `screen and (${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`; | |
| 2045 | 2037 | const mediaQueryResult = useMediaQuery(mediaQuery || void 0, view); |
| 2046 | 2038 | if (simulatedWidth) { |
| 2047 | 2039 | return OPERATOR_EVALUATORS[operator]( |
| 2048 | 2040 | BREAKPOINTS[breakpoint], |
| @@ -2059,8 +2051,17 @@ | ||
| 2059 | 2051 | function useResizeObserver(callback, resizeObserverOptions = {}) { |
| 2060 | 2052 | const callbackEvent = useEvent(callback); |
| 2061 | 2053 | const observedElementRef = (0, import_element22.useRef)(null); |
| 2062 | 2054 | const resizeObserverRef = (0, import_element22.useRef)(void 0); |
| 2055 | + (0, import_element22.useEffect)(() => { | |
| 2056 | + if (observedElementRef.current) { | |
| 2057 | + resizeObserverRef.current?.observe( | |
| 2058 | + observedElementRef.current, | |
| 2059 | + resizeObserverOptions | |
| 2060 | + ); | |
| 2061 | + } | |
| 2062 | + return () => resizeObserverRef.current?.disconnect(); | |
| 2063 | + }, []); | |
| 2063 | 2064 | return useEvent((element) => { |
| 2064 | 2065 | if (element === observedElementRef.current) { |
| 2065 | 2066 | return; |
| 2066 | 2067 | } |
| @@ -2185,20 +2186,13 @@ | ||
| 2185 | 2186 | // packages/compose/build-module/hooks/use-warn-on-change/index.mjs |
| 2186 | 2187 | function useWarnOnChange(object, prefix = "Change detection") { |
| 2187 | 2188 | const previousValues = usePrevious(object); |
| 2188 | 2189 | Object.entries(previousValues ?? []).forEach(([key, value]) => { |
| 2189 | - if (value !== object[ | |
| 2190 | - /** @type {keyof typeof object} */ | |
| 2191 | - key | |
| 2192 | - ]) { | |
| 2190 | + if (value !== object[key]) { | |
| 2193 | 2191 | console.warn( |
| 2194 | 2192 | `${prefix}: ${key} key changed:`, |
| 2195 | 2193 | value, |
| 2196 | - object[ | |
| 2197 | - /** @type {keyof typeof object} */ | |
| 2198 | - key | |
| 2199 | - ] | |
| 2200 | - /* eslint-enable jsdoc/check-types */ | |
| 2194 | + object[key] | |
| 2201 | 2195 | ); |
| 2202 | 2196 | } |
| 2203 | 2197 | }); |
| 2204 | 2198 | } |
| @@ -2320,12 +2314,9 @@ | ||
| 2320 | 2314 | } |
| 2321 | 2315 | } |
| 2322 | 2316 | function onDragEnter(event) { |
| 2323 | 2317 | event.preventDefault(); |
| 2324 | - if (element.contains( | |
| 2325 | - /** @type {Node} */ | |
| 2326 | - event.relatedTarget | |
| 2327 | - )) { | |
| 2318 | + if (element.contains(event.relatedTarget)) { | |
| 2328 | 2319 | return; |
| 2329 | 2320 | } |
| 2330 | 2321 | if (_onDragEnter) { |
| 2331 | 2322 | onDragEnterEvent(event); |
| @@ -2420,129 +2411,127 @@ | ||
| 2420 | 2411 | var import_dom3 = __toESM(require_dom(), 1); |
| 2421 | 2412 | var import_keycodes2 = __toESM(require_keycodes(), 1); |
| 2422 | 2413 | var DEFAULT_INIT_WINDOW_SIZE = 30; |
| 2423 | 2414 | function useFixedWindowList(elementRef, itemHeight, totalItems, options) { |
| 2424 | - const initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE; | |
| 2425 | - const useWindowing = options?.useWindowing ?? true; | |
| 2426 | - const [fixedListWindow, setFixedListWindow] = (0, import_element28.useState)({ | |
| 2427 | - visibleItems: initWindowSize, | |
| 2428 | - start: 0, | |
| 2429 | - end: initWindowSize, | |
| 2430 | - itemInView: (index) => { | |
| 2431 | - return index >= 0 && index <= initWindowSize; | |
| 2415 | + const { | |
| 2416 | + windowOverscan, | |
| 2417 | + useWindowing = true, | |
| 2418 | + initWindowSize = DEFAULT_INIT_WINDOW_SIZE, | |
| 2419 | + expandedState | |
| 2420 | + } = options ?? {}; | |
| 2421 | + const [fixedListWindow, setFixedListWindow] = (0, import_element28.useState)( | |
| 2422 | + { | |
| 2423 | + visibleItems: initWindowSize, | |
| 2424 | + start: 0, | |
| 2425 | + end: initWindowSize, | |
| 2426 | + itemInView: (index) => { | |
| 2427 | + return index >= 0 && index <= initWindowSize; | |
| 2428 | + } | |
| 2432 | 2429 | } |
| 2433 | - }); | |
| 2434 | - (0, import_element28.useLayoutEffect)(() => { | |
| 2435 | - if (!useWindowing) { | |
| 2430 | + ); | |
| 2431 | + const visibleItemsRef = (0, import_element28.useRef)(initWindowSize); | |
| 2432 | + const isFirstMeasurementRef = (0, import_element28.useRef)(true); | |
| 2433 | + const measureWindow = useEvent((initRender) => { | |
| 2434 | + const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current); | |
| 2435 | + if (!scrollContainer) { | |
| 2436 | 2436 | return; |
| 2437 | 2437 | } |
| 2438 | - const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current); | |
| 2439 | - const measureWindow = (initRender) => { | |
| 2440 | - if (!scrollContainer) { | |
| 2441 | - return; | |
| 2438 | + const visibleItems = Math.ceil( | |
| 2439 | + scrollContainer.clientHeight / itemHeight | |
| 2440 | + ); | |
| 2441 | + visibleItemsRef.current = visibleItems; | |
| 2442 | + const isFirstMeasurement = isFirstMeasurementRef.current; | |
| 2443 | + isFirstMeasurementRef.current = false; | |
| 2444 | + const overscan = initRender ? visibleItems : windowOverscan ?? visibleItems; | |
| 2445 | + const firstViewableIndex = Math.floor( | |
| 2446 | + scrollContainer.scrollTop / itemHeight | |
| 2447 | + ); | |
| 2448 | + const start = Math.max(0, firstViewableIndex - overscan); | |
| 2449 | + const end = Math.min( | |
| 2450 | + totalItems - 1, | |
| 2451 | + firstViewableIndex + visibleItems + overscan | |
| 2452 | + ); | |
| 2453 | + setFixedListWindow((lastWindow) => { | |
| 2454 | + if (lastWindow.start <= start && lastWindow.end >= end) { | |
| 2455 | + return lastWindow; | |
| 2442 | 2456 | } |
| 2443 | - const visibleItems = Math.ceil( | |
| 2444 | - scrollContainer.clientHeight / itemHeight | |
| 2445 | - ); | |
| 2446 | - const windowOverscan = initRender ? visibleItems : options?.windowOverscan ?? visibleItems; | |
| 2447 | - const firstViewableIndex = Math.floor( | |
| 2448 | - scrollContainer.scrollTop / itemHeight | |
| 2449 | - ); | |
| 2450 | - const start = Math.max(0, firstViewableIndex - windowOverscan); | |
| 2451 | - const end = Math.min( | |
| 2452 | - totalItems - 1, | |
| 2453 | - firstViewableIndex + visibleItems + windowOverscan | |
| 2454 | - ); | |
| 2455 | - setFixedListWindow((lastWindow) => { | |
| 2456 | - const nextWindow = { | |
| 2457 | - visibleItems, | |
| 2458 | - start, | |
| 2459 | - end, | |
| 2460 | - itemInView: (index) => { | |
| 2461 | - return start <= index && index <= end; | |
| 2462 | - } | |
| 2463 | - }; | |
| 2464 | - if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) { | |
| 2465 | - return nextWindow; | |
| 2457 | + if (isFirstMeasurement && lastWindow.start <= firstViewableIndex && lastWindow.end >= firstViewableIndex + visibleItems) { | |
| 2458 | + return lastWindow; | |
| 2459 | + } | |
| 2460 | + return { | |
| 2461 | + visibleItems, | |
| 2462 | + start, | |
| 2463 | + end, | |
| 2464 | + itemInView: (index) => { | |
| 2465 | + return start <= index && index <= end; | |
| 2466 | 2466 | } |
| 2467 | - return lastWindow; | |
| 2468 | - }); | |
| 2469 | - }; | |
| 2470 | - measureWindow(true); | |
| 2471 | - const debounceMeasureList = debounce(() => { | |
| 2472 | - measureWindow(); | |
| 2473 | - }, 16); | |
| 2474 | - scrollContainer?.addEventListener("scroll", debounceMeasureList); | |
| 2475 | - scrollContainer?.ownerDocument?.defaultView?.addEventListener( | |
| 2476 | - "resize", | |
| 2477 | - debounceMeasureList | |
| 2478 | - ); | |
| 2479 | - scrollContainer?.ownerDocument?.defaultView?.addEventListener( | |
| 2480 | - "resize", | |
| 2481 | - debounceMeasureList | |
| 2482 | - ); | |
| 2483 | - return () => { | |
| 2484 | - scrollContainer?.removeEventListener( | |
| 2485 | - "scroll", | |
| 2486 | - debounceMeasureList | |
| 2487 | - ); | |
| 2488 | - scrollContainer?.ownerDocument?.defaultView?.removeEventListener( | |
| 2489 | - "resize", | |
| 2490 | - debounceMeasureList | |
| 2491 | - ); | |
| 2492 | - }; | |
| 2493 | - }, [ | |
| 2494 | - itemHeight, | |
| 2495 | - elementRef, | |
| 2496 | - totalItems, | |
| 2497 | - options?.expandedState, | |
| 2498 | - options?.windowOverscan, | |
| 2499 | - useWindowing | |
| 2500 | - ]); | |
| 2501 | - (0, import_element28.useLayoutEffect)(() => { | |
| 2502 | - if (!useWindowing) { | |
| 2503 | - return; | |
| 2504 | - } | |
| 2505 | - const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current); | |
| 2506 | - const handleKeyDown = (event) => { | |
| 2467 | + }; | |
| 2468 | + }); | |
| 2469 | + }); | |
| 2470 | + const handleKeyDown = useEvent( | |
| 2471 | + (event, scrollContainer) => { | |
| 2507 | 2472 | switch (event.keyCode) { |
| 2508 | 2473 | case import_keycodes2.HOME: { |
| 2509 | - return scrollContainer?.scrollTo({ top: 0 }); | |
| 2474 | + return scrollContainer.scrollTo({ top: 0 }); | |
| 2510 | 2475 | } |
| 2511 | 2476 | case import_keycodes2.END: { |
| 2512 | - return scrollContainer?.scrollTo({ | |
| 2477 | + return scrollContainer.scrollTo({ | |
| 2513 | 2478 | top: totalItems * itemHeight |
| 2514 | 2479 | }); |
| 2515 | 2480 | } |
| 2516 | 2481 | case import_keycodes2.PAGEUP: { |
| 2517 | - return scrollContainer?.scrollTo({ | |
| 2518 | - top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight | |
| 2482 | + return scrollContainer.scrollTo({ | |
| 2483 | + top: scrollContainer.scrollTop - visibleItemsRef.current * itemHeight | |
| 2519 | 2484 | }); |
| 2520 | 2485 | } |
| 2521 | 2486 | case import_keycodes2.PAGEDOWN: { |
| 2522 | - return scrollContainer?.scrollTo({ | |
| 2523 | - top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight | |
| 2487 | + return scrollContainer.scrollTo({ | |
| 2488 | + top: scrollContainer.scrollTop + visibleItemsRef.current * itemHeight | |
| 2524 | 2489 | }); |
| 2525 | 2490 | } |
| 2526 | 2491 | } |
| 2527 | - }; | |
| 2528 | - scrollContainer?.ownerDocument?.defaultView?.addEventListener( | |
| 2529 | - "keydown", | |
| 2530 | - handleKeyDown | |
| 2531 | - ); | |
| 2492 | + } | |
| 2493 | + ); | |
| 2494 | + (0, import_element28.useLayoutEffect)(() => { | |
| 2495 | + if (!useWindowing) { | |
| 2496 | + return; | |
| 2497 | + } | |
| 2498 | + measureWindow(true); | |
| 2499 | + }, [ | |
| 2500 | + useWindowing, | |
| 2501 | + measureWindow, | |
| 2502 | + itemHeight, | |
| 2503 | + totalItems, | |
| 2504 | + windowOverscan, | |
| 2505 | + expandedState | |
| 2506 | + ]); | |
| 2507 | + (0, import_element28.useLayoutEffect)(() => { | |
| 2508 | + if (!useWindowing) { | |
| 2509 | + return; | |
| 2510 | + } | |
| 2511 | + const scrollContainer = (0, import_dom3.getScrollContainer)(elementRef.current); | |
| 2512 | + if (!scrollContainer) { | |
| 2513 | + return; | |
| 2514 | + } | |
| 2515 | + const { defaultView } = scrollContainer.ownerDocument; | |
| 2516 | + const onMeasure = () => measureWindow(); | |
| 2517 | + const onKeyDown = (event) => handleKeyDown(event, scrollContainer); | |
| 2518 | + scrollContainer.addEventListener("scroll", onMeasure); | |
| 2519 | + defaultView?.addEventListener("resize", onMeasure); | |
| 2520 | + defaultView?.addEventListener("keydown", onKeyDown); | |
| 2532 | 2521 | return () => { |
| 2533 | - scrollContainer?.ownerDocument?.defaultView?.removeEventListener( | |
| 2534 | - "keydown", | |
| 2535 | - handleKeyDown | |
| 2536 | - ); | |
| 2522 | + scrollContainer.removeEventListener("scroll", onMeasure); | |
| 2523 | + defaultView?.removeEventListener("resize", onMeasure); | |
| 2524 | + defaultView?.removeEventListener("keydown", onKeyDown); | |
| 2537 | 2525 | }; |
| 2538 | 2526 | }, [ |
| 2527 | + useWindowing, | |
| 2528 | + elementRef, | |
| 2529 | + itemHeight, | |
| 2539 | 2530 | totalItems, |
| 2540 | - itemHeight, | |
| 2541 | - elementRef, | |
| 2542 | - fixedListWindow.visibleItems, | |
| 2543 | - useWindowing, | |
| 2544 | - options?.expandedState | |
| 2531 | + expandedState, | |
| 2532 | + measureWindow, | |
| 2533 | + handleKeyDown | |
| 2545 | 2534 | ]); |
| 2546 | 2535 | return [fixedListWindow, setFixedListWindow]; |
| 2547 | 2536 | } |
| 2548 | 2537 | |
| @@ -2558,6 +2547,8 @@ | ||
| 2558 | 2547 | ); |
| 2559 | 2548 | return (0, import_element29.useSyncExternalStore)(subscribe, getValue, getValue); |
| 2560 | 2549 | } |
| 2561 | 2550 | return __toCommonJS(index_exports); |
| 2551 | +})(); | |
| 2552 | +(window.wp ||= {}).compose = wp.compose; | |
| 2562 | 2553 | })(); |
| 2563 | 2554 | //# sourceMappingURL=index.js.map |