Private
Public Access
1
0

feat: Fluent UI Outlook Lite + connections mockup

This commit is contained in:
2026-04-14 18:52:25 +00:00
parent 1199eff6c3
commit dfa4010406
34820 changed files with 1003813 additions and 205 deletions

View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/hooks.types.ts"],"sourcesContent":["import * as React from 'react';\nimport { DynamicVirtualizerContextProps } from '../Utilities';\n\n/**\n * @deprecated migrated to \\@fluentui\\-contrib/react\\-virtualizer for stable release.\n */\nexport type VirtualizerMeasureProps = {\n defaultItemSize: number;\n direction?: 'vertical' | 'horizontal';\n\n /**\n * Override recommended number of buffer items\n */\n bufferItems?: number;\n\n /**\n * Override recommended buffer size (px)\n */\n bufferSize?: number;\n};\n\n/**\n * @deprecated migrated to \\@fluentui\\-contrib/react\\-virtualizer for stable release.\n */\nexport type VirtualizerMeasureDynamicProps = {\n defaultItemSize: number;\n virtualizerContext: DynamicVirtualizerContextProps;\n numItems: number;\n getItemSize: (index: number) => number;\n direction?: 'vertical' | 'horizontal';\n\n /**\n * Override recommended number of buffer items\n */\n bufferItems?: number;\n\n /**\n * Override recommended buffer size (px)\n */\n bufferSize?: number;\n};\n\n/**\n * @deprecated migrated to \\@fluentui\\-contrib/react\\-virtualizer for stable release.\n */\nexport type VirtualizerStaticPaginationProps = {\n itemSize: number;\n axis?: 'vertical' | 'horizontal';\n};\n\n/**\n * Props to be passed into dynamic virtualization hooks\n * All props can be acquired from useVirtualizer hooks themselves and passed in\n * @deprecated migrated to \\@fluentui\\-contrib/react\\-virtualizer for stable release.\n */\nexport type VirtualizerDynamicPaginationProps = {\n /**\n * An array that tracks the sizing of each item in virtualizer cumulatively\n */\n progressiveItemSizes: React.RefObject<number[]> | undefined;\n /**\n * The current starting index of the virtualizer's DOM elements\n */\n currentIndex: number;\n /**\n * The axis we should paginate on (should match virtualizer's axis)\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * The current length of Virtualizer's actual DOM elements\n */\n virtualizerLength: number;\n};\n\n/**\n * Additional direct Ref prevents reading old resize entry data\n * Backwards compatible with ResizeObserverCallback if preferred\n * @deprecated migrated to \\@fluentui\\-contrib/react\\-virtualizer for stable release.\n */\nexport interface ResizeCallbackWithRef {\n (\n entries: ResizeObserverEntry[],\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n\n observer: ResizeObserver,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n scrollRef?: React.MutableRefObject<HTMLElement | null>,\n ): void;\n}\n"],"names":["React"],"mappings":";;;;;iEAAuB,QAAQ"}

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
createResizeObserverFromDocument: function() {
return _useMeasureList.createResizeObserverFromDocument;
},
getRTLRootMargin: function() {
return _useIntersectionObserver.getRTLRootMargin;
},
useDynamicVirtualizerMeasure: function() {
return _useDynamicVirtualizerMeasure.useDynamicVirtualizerMeasure;
},
useIntersectionObserver: function() {
return _useIntersectionObserver.useIntersectionObserver;
},
useMeasureList: function() {
return _useMeasureList.useMeasureList;
},
useResizeObserverRef_unstable: function() {
return _useResizeObserverRef.useResizeObserverRef_unstable;
},
useStaticVirtualizerMeasure: function() {
return _useVirtualizerMeasure.useStaticVirtualizerMeasure;
}
});
const _useIntersectionObserver = require("./useIntersectionObserver");
const _useVirtualizerMeasure = require("./useVirtualizerMeasure");
const _useDynamicVirtualizerMeasure = require("./useDynamicVirtualizerMeasure");
const _useResizeObserverRef = require("./useResizeObserverRef");
const _useMeasureList = require("./useMeasureList");

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/index.ts"],"sourcesContent":["export { getRTLRootMargin, useIntersectionObserver } from './useIntersectionObserver';\nexport { useStaticVirtualizerMeasure } from './useVirtualizerMeasure';\nexport { useDynamicVirtualizerMeasure } from './useDynamicVirtualizerMeasure';\nexport { useResizeObserverRef_unstable } from './useResizeObserverRef';\nexport type {\n ResizeCallbackWithRef,\n VirtualizerDynamicPaginationProps,\n VirtualizerMeasureDynamicProps,\n VirtualizerMeasureProps,\n VirtualizerStaticPaginationProps,\n} from './hooks.types';\nexport type { IndexedResizeCallbackElement } from './useMeasureList';\nexport { createResizeObserverFromDocument, useMeasureList } from './useMeasureList';\n"],"names":["getRTLRootMargin","useIntersectionObserver","useStaticVirtualizerMeasure","useDynamicVirtualizerMeasure","useResizeObserverRef_unstable","createResizeObserverFromDocument","useMeasureList"],"mappings":";;;;;;;;;;;;eAYSK,gDAAgC;;;eAZhCL,yCAAgB;;;eAEhBG,0DAA4B;;;eAFVF,gDAAuB;;;eAYPK,8BAAc;;;eAThDF,mDAA6B;;;eAF7BF,kDAA2B;;;yCADsB,4BAA4B;uCAC1C,0BAA0B;8CACzB,iCAAiC;sCAChC,yBAAyB;gCASN,mBAAmB"}

View File

@@ -0,0 +1,132 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useDynamicVirtualizerPagination", {
enumerable: true,
get: function() {
return useDynamicVirtualizerPagination;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactutilities = require("@fluentui/react-utilities");
const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
'use no memo';
const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
const lastScrollPos = _react.useRef(-1);
const lastIndexScrolled = _react.useRef(-1);
const scrollContainer = _react.useRef(null);
const clearListeners = ()=>{
if (scrollContainer.current) {
scrollContainer.current.removeEventListener('scroll', onScroll);
scrollContainer.current = null;
clearScrollTimer();
}
};
_react.useEffect(()=>{
return ()=>{
clearListeners();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
/**
* Handle scroll stop event and paginate to the closest item
* If the closest item is the same as the previous scroll end
* we paginate to the next/previous one based on direction
*
* Users/Virtualizer-Hooks must pass in a cumulative array of sizes
* This prevents the need to recalculate and ensures size arrays are synced externally
*/ const onScrollEnd = _react.useCallback(()=>{
if (!scrollContainer.current || !paginationEnabled || !(progressiveItemSizes === null || progressiveItemSizes === void 0 ? void 0 : progressiveItemSizes.current)) {
// No container found
return;
}
const currentScrollPos = Math.round(axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft);
let closestItemPos = 0;
let closestItem = 0;
const endItem = Math.min(currentIndex + virtualizerLength, progressiveItemSizes.current.length);
for(let i = currentIndex; i < endItem - 1; i++){
if (currentScrollPos <= progressiveItemSizes.current[i + 1] && currentScrollPos >= progressiveItemSizes.current[i]) {
// Found our in between position
const distanceToPrev = Math.abs(currentScrollPos - progressiveItemSizes.current[i]);
const distanceToNext = Math.abs(progressiveItemSizes.current[i + 1] - currentScrollPos);
if (distanceToPrev < distanceToNext) {
closestItem = i;
} else {
closestItem = i + 1;
}
break;
}
}
let nextItem;
if (Math.round(closestItem - lastIndexScrolled.current) === 0) {
// Special case for go to next/previous with minimum amount of scroll needed
const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;
// This will also handle a case where we scrolled to the exact correct position (noop)
const isSecondaryScroll = Math.round(lastScrollPos.current - currentScrollPos) === 0;
const posMod = isSecondaryScroll ? 0 : nextTarget;
nextItem = closestItem + posMod;
} else {
// Pagination for anything else can just jump to the closest!
nextItem = closestItem;
}
// Safeguard nextItem
nextItem = Math.min(Math.max(0, nextItem), progressiveItemSizes.current.length);
closestItemPos = progressiveItemSizes.current[nextItem];
if (axis === 'vertical') {
scrollContainer.current.scrollTo({
top: closestItemPos,
behavior: 'smooth'
});
} else {
scrollContainer.current.scrollTo({
left: closestItemPos,
behavior: 'smooth'
});
}
lastScrollPos.current = progressiveItemSizes.current[nextItem];
lastIndexScrolled.current = nextItem;
}, [
paginationEnabled,
currentIndex,
scrollContainer,
virtualizerLength,
axis,
progressiveItemSizes
]);
/**
* On scroll timer that will continuously delay callback until scrolling stops
*/ const onScroll = _react.useCallback(()=>{
clearScrollTimer();
setScrollTimer(onScrollEnd, 100);
}, [
onScrollEnd,
clearScrollTimer,
setScrollTimer
]);
/**
* Pagination ref will ensure we attach listeners to containers on change
* It is returned from hook and merged into the scroll container externally
*/ const paginationRef = _react.useCallback((instance)=>{
if (!paginationEnabled) {
clearListeners();
scrollContainer.current = null;
return;
}
if (scrollContainer.current !== instance) {
clearListeners();
scrollContainer.current = instance;
if (scrollContainer.current) {
scrollContainer.current.addEventListener('scroll', onScroll);
}
}
}, [
onScroll,
onScrollEnd,
paginationEnabled
]);
return paginationRef;
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,134 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useDynamicVirtualizerMeasure", {
enumerable: true,
get: function() {
return useDynamicVirtualizerMeasure;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _reactutilities = require("@fluentui/react-utilities");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _useResizeObserverRef = require("./useResizeObserverRef");
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const useDynamicVirtualizerMeasure = (virtualizerProps)=>{
const { defaultItemSize, direction = 'vertical', numItems, getItemSize, bufferItems, bufferSize, virtualizerContext } = virtualizerProps;
const [state, setState] = _react.useState({
virtualizerLength: 0,
virtualizerBufferItems: 0,
virtualizerBufferSize: 0
});
const containerSizeRef = _react.useRef(0);
const scrollPosition = _react.useRef(0);
const { virtualizerLength, virtualizerBufferItems, virtualizerBufferSize } = state;
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
const container = _react.useRef(null);
const handleScrollResize = _react.useCallback((scrollRef)=>{
if (!(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
// Error? ignore?
return;
}
if (scrollRef.current !== (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body)) {
// We have a local scroll container
containerSizeRef.current = direction === 'vertical' ? scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.getBoundingClientRect().height : scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.getBoundingClientRect().width;
} else if (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) {
var _targetDocument_defaultView, _targetDocument_defaultView1;
// If our scroll ref is the document body, we should check window height
containerSizeRef.current = direction === 'vertical' ? targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.innerHeight : targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.innerWidth;
}
let indexSizer = 0;
let i = 0;
let length = 0;
const startIndex = virtualizerContext.contextIndex;
const sizeToBeat = containerSizeRef.current + virtualizerBufferSize * 2;
while(indexSizer <= sizeToBeat && i + startIndex < numItems){
const iItemSize = getItemSize(startIndex + i);
if (virtualizerContext.childProgressiveSizes.current.length < numItems) {
/* We are in unknown territory, either an initial render or an update
in virtualizer item length has occurred.
We need to let the new items render first then we can accurately assess.*/ return virtualizerLength - virtualizerBufferSize * 2;
}
const currentScrollPos = scrollPosition.current;
const currentItemPos = virtualizerContext.childProgressiveSizes.current[startIndex + i] - iItemSize;
if (currentScrollPos > currentItemPos + iItemSize) {
// The item isn't in view, ignore for now.
i++;
continue;
} else if (currentScrollPos > currentItemPos) {
// The item is partially out of view, ignore the out of bounds portion
const variance = currentItemPos + iItemSize - currentScrollPos;
indexSizer += variance;
} else {
// Item is in view
indexSizer += iItemSize;
}
// Increment
i++;
length++;
}
/*
* Number of items to append at each end, i.e. 'preload' each side before entering view.
* Minimum: 2 - we give slightly more buffer for dynamic version.
*/ const newBufferItems = bufferItems !== null && bufferItems !== void 0 ? bufferItems : Math.max(Math.ceil(length / 3), 1);
/*
* This is how far we deviate into the bufferItems to detect a redraw.
*/ const newBufferSize = bufferSize !== null && bufferSize !== void 0 ? bufferSize : Math.max(defaultItemSize / 2, 1);
const totalLength = length + newBufferItems * 2;
setState({
virtualizerLength: totalLength,
virtualizerBufferSize: newBufferSize,
virtualizerBufferItems: newBufferItems
});
}, [
bufferItems,
bufferSize,
defaultItemSize,
direction,
getItemSize,
numItems,
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body,
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView,
virtualizerBufferSize,
virtualizerContext.childProgressiveSizes,
virtualizerContext.contextIndex,
virtualizerLength
]);
const resizeCallback = _react.useCallback((_entries, _observer, scrollRef)=>{
if (scrollRef) {
handleScrollResize(scrollRef);
}
}, [
handleScrollResize
]);
const scrollRef = (0, _reactutilities.useMergedRefs)(container, (0, _useResizeObserverRef.useResizeObserverRef_unstable)(resizeCallback));
(0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
if (virtualizerContext.contextIndex + virtualizerLength < numItems) {
// Avoid re-rendering/re-calculating when the end index has already been reached
handleScrollResize(container);
}
}, [
handleScrollResize,
numItems,
virtualizerContext.contextIndex,
virtualizerLength
]);
const updateScrollPosition = _react.useCallback((_scrollPosition)=>{
scrollPosition.current = _scrollPosition;
// Check if our vLength's need recalculating
handleScrollResize(scrollRef);
}, [
handleScrollResize,
scrollRef
]);
return {
virtualizerLength,
bufferItems: virtualizerBufferItems,
bufferSize: virtualizerBufferSize,
scrollRef,
containerSizeRef,
updateScrollPosition
};
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,135 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
getRTLRootMargin: function() {
return getRTLRootMargin;
},
useIntersectionObserver: function() {
return useIntersectionObserver;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactutilities = require("@fluentui/react-utilities");
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _useMutationObserver = require("./useMutationObserver");
const { useCallback, useState, useRef } = _react;
const getRTLRootMargin = (ltrRootMargin, target, win)=>{
if (target && win) {
// get the computed dir for the target element
const newDir = win.getComputedStyle(target).direction;
// If we're in rtl reading direction, we might need to flip the margins on the left/right sides
if (newDir === 'rtl') {
let newMargin = ltrRootMargin;
const splitMargins = ltrRootMargin.split(' ');
// We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.
if (splitMargins.length === 4) {
newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;
}
return newMargin;
} else {
return ltrRootMargin;
}
}
return ltrRootMargin;
};
const useIntersectionObserver = (callback, options)=>{
'use no memo';
// TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286
const observer = useRef(undefined);
const [observerList, setObserverList] = useState();
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
var _options_rootMargin;
// set the initial init with corrected margins based on the observed root's calculated reading direction.
const [observerInit, setObserverInit] = useState(options && {
...options,
rootMargin: getRTLRootMargin((_options_rootMargin = options.rootMargin) !== null && _options_rootMargin !== void 0 ? _options_rootMargin : '0px', options.root, win)
});
var _options_rootMargin1;
// We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.
const ltrRootMargin = useRef((_options_rootMargin1 = options === null || options === void 0 ? void 0 : options.rootMargin) !== null && _options_rootMargin1 !== void 0 ? _options_rootMargin1 : '0px');
// Callback function to execute when mutations are observed
const mutationObserverCallback = useCallback((mutationList)=>{
for (const mutation of mutationList){
// Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.
if (mutation.type === 'attributes' && mutation.attributeName === 'dir' && (options === null || options === void 0 ? void 0 : options.root) && mutation.target.contains(options === null || options === void 0 ? void 0 : options.root)) {
setObserverInit({
...observerInit,
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root, win)
});
}
}
}, [
ltrRootMargin,
observerInit,
options === null || options === void 0 ? void 0 : options.root,
win
]);
// Mutation observer for dir attribute changes in the document
(0, _useMutationObserver.useMutationObserver)(targetDocument, mutationObserverCallback, {
attributes: true,
subtree: true,
attributeFilter: [
'dir'
]
});
// Observer elements in passed in list and clean up previous list
// This effect is only triggered when observerList is updated
(0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
if (!win) {
return;
}
observer.current = new win.IntersectionObserver(callback, {
...observerInit,
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root, win)
});
// If we have an instance of IO and a list with elements, observer the elements
if (observer.current && observerList && observerList.length > 0) {
observerList.forEach((element)=>{
var _observer_current;
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(element);
});
}
// clean up previous elements being listened to
return ()=>{
if (observer.current) {
observer.current.disconnect();
}
};
}, [
observerList,
observerInit,
callback,
win
]);
// Do not use internally, we need to track external settings only here
const setObserverInitExternal = useCallback((newInit)=>{
var _newInit_rootMargin;
// Since we know this is coming from consumers, we can store this value as LTR somewhat safely.
ltrRootMargin.current = (_newInit_rootMargin = newInit === null || newInit === void 0 ? void 0 : newInit.rootMargin) !== null && _newInit_rootMargin !== void 0 ? _newInit_rootMargin : '0px';
// Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin
setObserverInit({
...newInit,
rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit === null || newInit === void 0 ? void 0 : newInit.root, win)
});
}, [
ltrRootMargin,
setObserverInit,
win
]);
return {
setObserverList,
setObserverInit: setObserverInitExternal,
observer
};
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,135 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
createResizeObserverFromDocument: function() {
return createResizeObserverFromDocument;
},
useMeasureList: function() {
return useMeasureList;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {
const widthArray = _react.useRef(new Array(totalLength).fill(defaultItemSize));
const heightArray = _react.useRef(new Array(totalLength).fill(defaultItemSize));
const refArray = _react.useRef([]);
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
// This lets us trigger updates when a size change occurs.
const sizeUpdateCount = _react.useRef(0);
// the handler for resize observer
const handleIndexUpdate = _react.useCallback((index)=>{
var _refArray_current_index;
let isChanged = false;
const boundClientRect = (_refArray_current_index = refArray.current[index]) === null || _refArray_current_index === void 0 ? void 0 : _refArray_current_index.getBoundingClientRect();
const containerWidth = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.width;
if (containerWidth !== widthArray.current[currentIndex + index]) {
isChanged = true;
}
widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;
const containerHeight = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.height;
if (containerHeight !== heightArray.current[currentIndex + index]) {
isChanged = true;
}
heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;
if (isChanged) {
sizeUpdateCount.current = sizeUpdateCount.current + 1;
}
}, [
currentIndex,
defaultItemSize,
sizeUpdateCount
]);
const handleElementResizeCallback = (entries)=>{
for (const entry of entries){
const target = entry.target;
// Call the elements own resize handler (indexed)
target.handleResize();
}
};
_react.useEffect(()=>{
const newHeightLength = totalLength - heightArray.current.length;
const newWidthLength = totalLength - widthArray.current.length;
/* Ensure we grow or truncate arrays with prior properties,
keeping the existing values is important for whitespace assumptions.
Even if items in the 'middle' are deleted, we will recalc the whitespace as it is explored.*/ if (newWidthLength > 0) {
widthArray.current = widthArray.current.concat(new Array(newWidthLength).fill(defaultItemSize));
} else if (newWidthLength < 0) {
widthArray.current = widthArray.current.slice(0, totalLength);
}
if (newHeightLength > 0) {
heightArray.current = heightArray.current.concat(new Array(newHeightLength).fill(defaultItemSize));
} else if (newHeightLength < 0) {
heightArray.current = heightArray.current.slice(0, totalLength);
}
}, [
defaultItemSize,
totalLength
]);
// Keep the reference of ResizeObserver as a ref, as it should live through renders
const resizeObserver = _react.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));
/* createIndexedRef provides a dynamic function to create an undefined number of refs at render time
* these refs then provide an indexed callback via attaching 'handleResize' to the element itself
* this function is then called on resize by handleElementResize and relies on indexing
* to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.
*/ const createIndexedRef = _react.useCallback((index)=>{
const measureElementRef = (el)=>{
if (!targetDocument || !resizeObserver.current) {
return;
}
if (el) {
el.handleResize = ()=>{
handleIndexUpdate(index);
};
}
// cleanup previous container
if (refArray.current[index] !== undefined && refArray.current[index] !== null) {
resizeObserver.current.unobserve(refArray.current[index]);
}
refArray.current[index] = undefined;
if (el) {
refArray.current[index] = el;
resizeObserver.current.observe(el);
handleIndexUpdate(index);
}
};
return measureElementRef;
}, [
handleIndexUpdate,
resizeObserver,
targetDocument
]);
_react.useEffect(()=>{
const _resizeObserver = resizeObserver;
return ()=>{
var _resizeObserver_current;
return (_resizeObserver_current = _resizeObserver.current) === null || _resizeObserver_current === void 0 ? void 0 : _resizeObserver_current.disconnect();
};
}, [
resizeObserver
]);
return {
widthArray,
heightArray,
createIndexedRef,
refArray,
sizeUpdateCount: sizeUpdateCount.current
};
}
function createResizeObserverFromDocument(targetDocument, callback) {
var _targetDocument_defaultView;
if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {
return null;
}
return new targetDocument.defaultView.ResizeObserver(callback);
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,48 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useMutationObserver", {
enumerable: true,
get: function() {
return useMutationObserver;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const { useRef, useEffect } = _react;
const useMutationObserver = (target, callback, options)=>{
'use no memo';
// TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286
const observer = useRef(undefined);
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
useEffect(()=>{
if (!win) {
return;
}
// Create an observer instance linked to the callback function
observer.current = new win.MutationObserver(callback);
}, [
callback,
win
]);
useEffect(()=>{
if (target) {
var _observer_current;
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(target, options);
}
return ()=>{
var _observer_current;
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.disconnect();
};
}, [
target,
options
]);
return {
observer
};
};

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useMutationObserver.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useRef, useEffect } = React;\n\n/**\n * @deprecated migrated to \\@fluentui\\-contrib/react\\-virtualizer for stable release.\n */\nexport const useMutationObserver = (\n target: Element | Document | undefined,\n callback: MutationCallback,\n options?: MutationObserverInit,\n): {\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n observer: React.MutableRefObject<MutationObserver | undefined>;\n} => {\n 'use no memo';\n\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n\n const observer = useRef<MutationObserver | undefined>(undefined);\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n useEffect(() => {\n if (!win) {\n return;\n }\n // Create an observer instance linked to the callback function\n observer.current = new win.MutationObserver(callback);\n }, [callback, win]);\n\n useEffect(() => {\n if (target) {\n // Start observing the target node for configured mutations\n observer.current?.observe(target, options);\n }\n\n return () => {\n observer.current?.disconnect();\n };\n }, [target, options]);\n\n return { observer };\n};\n"],"names":["React","useFluent_unstable","useFluent","useRef","useEffect","useMutationObserver","target","callback","options","observer","undefined","targetDocument","win","defaultView","current","MutationObserver","observe","disconnect"],"mappings":"AAAA;;;;;+BAUaK;;;;;;;iEARU,QAAQ;qCACiB,kCAAkC;AAElF,MAAM,EAAEF,MAAM,EAAEC,SAAS,EAAE,GAAGJ;AAKvB,4BAA4B,CACjCM,QACAC,UACAC;IAKA;IAEA,8FAA8F;IAE9F,MAAMC,WAAWN,OAAqCO;IACtD,MAAM,EAAEC,cAAc,EAAE,OAAGT,uCAAAA;IAC3B,MAAMU,MAAMD,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBE,WAAW;IAEvCT,UAAU;QACR,IAAI,CAACQ,KAAK;YACR;QACF;QACA,8DAA8D;QAC9DH,SAASK,OAAO,GAAG,IAAIF,IAAIG,gBAAgB,CAACR;IAC9C,GAAG;QAACA;QAAUK;KAAI;IAElBR,UAAU;QACR,IAAIE,QAAQ;gBACV,AACAG,2DAD2D;aAC3DA,oBAAAA,SAASK,OAAAA,AAAO,MAAA,QAAhBL,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kBAAkBO,OAAO,CAACV,QAAQE;QACpC;QAEA,OAAO;gBACLC;aAAAA,oBAAAA,SAASK,OAAAA,AAAO,MAAA,QAAhBL,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kBAAkBQ,UAAU;QAC9B;IACF,GAAG;QAACX;QAAQE;KAAQ;IAEpB,OAAO;QAAEC;IAAS;AACpB,EAAE"}

View File

@@ -0,0 +1,69 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useResizeObserverRef_unstable", {
enumerable: true,
get: function() {
return useResizeObserverRef_unstable;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _debounce = require("../utilities/debounce");
const _createResizeObserverFromDocument = require("../utilities/createResizeObserverFromDocument");
const useResizeObserverRef_unstable = (resizeCallback)=>{
'use no memo';
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
const container = _react.useRef(null);
const containerHeightRef = _react.useRef(0);
const containerWidthRef = _react.useRef(0);
// the handler for resize observer
// TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286
const handleResize = (0, _debounce.debounce)((entries, observer)=>{
var _container_current, _container_current1;
const containerHeight = (_container_current = container.current) === null || _container_current === void 0 ? void 0 : _container_current.clientHeight;
const containerWidth = (_container_current1 = container.current) === null || _container_current1 === void 0 ? void 0 : _container_current1.clientWidth;
// Our resize observer will fire on scroll resize, let index change handle that instead.
if (containerHeightRef.current !== containerHeight || containerWidth !== containerWidthRef.current) {
containerWidthRef.current = containerWidth !== null && containerWidth !== void 0 ? containerWidth : 0;
containerHeightRef.current = containerHeight !== null && containerHeight !== void 0 ? containerHeight : 0;
resizeCallback(entries, observer, container);
}
});
// Keep the reference of ResizeObserver in the state, as it should live through renders
const [resizeObserver, setResizeObserver] = _react.useState(()=>(0, _createResizeObserverFromDocument.createResizeObserverFromDocument)(targetDocument, handleResize));
_react.useEffect(()=>{
// Update our state when resizeCallback changes
container.current = null;
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
setResizeObserver(()=>(0, _createResizeObserverFromDocument.createResizeObserverFromDocument)(targetDocument, handleResize));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
resizeCallback,
targetDocument
]);
_react.useEffect(()=>{
return ()=>{
container.current = null;
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const scrollRef = _react.useCallback((instance)=>{
if (container.current !== instance) {
if (container.current) {
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.unobserve(container.current);
}
container.current = instance;
if (container.current) {
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(container.current);
}
}
}, [
resizeObserver
]);
return scrollRef;
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,108 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useStaticVirtualizerPagination", {
enumerable: true,
get: function() {
return useStaticVirtualizerPagination;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactutilities = require("@fluentui/react-utilities");
const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
'use no memo';
const { itemSize, axis = 'vertical' } = virtualizerProps;
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
const lastScrollPos = _react.useRef(0);
const lastIndexScrolled = _react.useRef(0);
const scrollContainer = _react.useRef(null);
const clearListeners = ()=>{
if (scrollContainer.current) {
scrollContainer.current.removeEventListener('scroll', onScroll);
scrollContainer.current = null;
clearScrollTimer();
}
};
_react.useEffect(()=>{
return ()=>{
clearListeners();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
/**
* Handle scroll stop event and paginate to the closest item
* If the closest item is the same as the previous scroll end
* we paginate to the next/previous one based on direction
*/ const onScrollEnd = _react.useCallback(()=>{
if (!scrollContainer.current || !paginationEnabled) {
// No container found
return;
}
const currentScrollPos = Math.round(axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft);
const closestItem = Math.round(currentScrollPos / itemSize);
let nextItem = 0;
if (Math.round(closestItem - lastIndexScrolled.current) === 0) {
// Special case for go to next/previous with minimum amount of scroll needed
const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;
const isSecondaryScroll = lastScrollPos.current === currentScrollPos;
const posMod = isSecondaryScroll ? 0 : nextTarget;
nextItem = closestItem + posMod;
} else {
// Pagination for anything else can just jump to the closest!
nextItem = closestItem;
}
const nextItemPos = nextItem * itemSize;
if (axis === 'vertical') {
scrollContainer.current.scrollTo({
top: nextItemPos,
behavior: 'smooth'
});
} else {
scrollContainer.current.scrollTo({
left: nextItemPos,
behavior: 'smooth'
});
}
lastScrollPos.current = nextItemPos;
lastIndexScrolled.current = nextItem;
}, [
paginationEnabled,
axis,
itemSize
]);
/**
* On scroll timer that will continuously delay callback until scrolling stops
*/ const onScroll = _react.useCallback(()=>{
clearScrollTimer();
setScrollTimer(onScrollEnd, 100);
}, [
onScrollEnd,
clearScrollTimer,
setScrollTimer
]);
/**
* Pagination ref will ensure we attach listeners to containers on change
* It is returned from hook and merged into the scroll container externally
*/ const paginationRef = _react.useCallback((instance)=>{
if (!paginationEnabled) {
clearListeners();
scrollContainer.current = null;
return;
}
if (scrollContainer.current !== instance) {
clearListeners();
scrollContainer.current = instance;
if (scrollContainer.current) {
scrollContainer.current.addEventListener('scroll', onScroll);
}
}
}, [
onScroll,
onScrollEnd,
paginationEnabled
]);
return paginationRef;
};

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,70 @@
'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useStaticVirtualizerMeasure", {
enumerable: true,
get: function() {
return useStaticVirtualizerMeasure;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _useResizeObserverRef = require("./useResizeObserverRef");
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const useStaticVirtualizerMeasure = (virtualizerProps)=>{
const { defaultItemSize, direction = 'vertical', bufferItems, bufferSize } = virtualizerProps;
const [state, setState] = _react.useState({
virtualizerLength: 0,
_bufferSize: 0,
_bufferItems: 0
});
const containerSizeRef = _react.useRef(0);
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
const { virtualizerLength, _bufferItems, _bufferSize } = state;
const resizeCallback = _react.useCallback((_entries, _observer, scrollRef)=>{
if (!(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
return;
}
if (scrollRef.current !== (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body)) {
// We have a local scroll container
containerSizeRef.current = direction === 'vertical' ? scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.getBoundingClientRect().height : scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.getBoundingClientRect().width;
} else if (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) {
var _targetDocument_defaultView, _targetDocument_defaultView1;
// If our scroll ref is the document body, we should check window height
containerSizeRef.current = direction === 'vertical' ? targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.innerHeight : targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.innerWidth;
}
/*
* Number of items required to cover viewport.
*/ const length = Math.ceil(containerSizeRef.current / defaultItemSize + 1);
/*
* Number of items to append at each end, i.e. 'preload' each side before entering view.
* Minimum: 1
*/ const newBufferItems = bufferItems !== null && bufferItems !== void 0 ? bufferItems : Math.max(Math.ceil(length / 4), 1);
/*
* This is how far we deviate into the bufferItems to detect a redraw.
*/ const newBufferSize = bufferSize !== null && bufferSize !== void 0 ? bufferSize : Math.max(defaultItemSize / 2.0, 1);
const totalLength = length + newBufferItems * 2;
setState({
virtualizerLength: totalLength,
_bufferItems: newBufferItems,
_bufferSize: newBufferSize
});
}, [
bufferItems,
bufferSize,
defaultItemSize,
direction,
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body,
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView
]);
const scrollRef = (0, _useResizeObserverRef.useResizeObserverRef_unstable)(resizeCallback);
return {
virtualizerLength,
bufferItems: _bufferItems,
bufferSize: _bufferSize,
scrollRef,
containerSizeRef
};
};

File diff suppressed because one or more lines are too long