first_commit

This commit is contained in:
2026-01-12 12:43:50 +01:00
parent c75b3e9563
commit 69e186a7f1
15289 changed files with 1616360 additions and 1944 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,174 @@
/// <reference types="react" />
import { Dimensions } from '@floating-ui/react-dom';
import { FocusableElement } from 'tabbable';
import * as React from 'react';
import type { UseFloatingReturn } from '@floating-ui/react-dom';
import useModernLayoutEffect from 'use-isomorphic-layout-effect';
import type { VirtualElement } from '@floating-ui/react-dom';
export declare function activeElement(doc: Document): Element | null;
declare type AnyFunction = (...args: any[]) => any;
export declare function contains(parent?: Element | null, child?: Element | null): boolean;
declare interface ContextData {
openEvent?: Event;
floatingContext?: FloatingContext;
/** @deprecated use `onTypingChange` prop in `useTypeahead` */
typing?: boolean;
[key: string]: any;
}
/** For each cell index, gets the item index that occupies that cell */
export declare function createGridCellMap(sizes: Dimensions[], cols: number, dense: boolean): (number | undefined)[];
declare type DisabledIndices = Array<number> | ((index: number) => boolean);
export declare function disableFocusInside(container: HTMLElement): void;
export declare function enableFocusInside(container: HTMLElement): void;
declare interface ExtendedElements<RT> {
reference: ReferenceType | null;
floating: HTMLElement | null;
domReference: NarrowedElement<RT> | null;
}
declare interface ExtendedRefs<RT> {
reference: React.MutableRefObject<ReferenceType | null>;
floating: React.MutableRefObject<HTMLElement | null>;
domReference: React.MutableRefObject<NarrowedElement<RT> | null>;
setReference(node: RT | null): void;
setFloating(node: HTMLElement | null): void;
setPositionReference(node: ReferenceType | null): void;
}
export declare function findNonDisabledListIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, { startingIndex, decrement, disabledIndices, amount, }?: {
startingIndex?: number;
decrement?: boolean;
disabledIndices?: DisabledIndices;
amount?: number;
}): number;
declare type FloatingContext<RT extends ReferenceType = ReferenceType> = Omit<UseFloatingReturn<RT>, 'refs' | 'elements'> & {
open: boolean;
onOpenChange(open: boolean, event?: Event, reason?: OpenChangeReason): void;
events: FloatingEvents;
dataRef: React.MutableRefObject<ContextData>;
nodeId: string | undefined;
floatingId: string | undefined;
refs: ExtendedRefs<RT>;
elements: ExtendedElements<RT>;
};
declare interface FloatingEvents {
emit<T extends string>(event: T, data?: any): void;
on(event: string, handler: (data: any) => void): void;
off(event: string, handler: (data: any) => void): void;
}
declare interface FloatingNodeType<RT extends ReferenceType = ReferenceType> {
id: string | undefined;
parentId: string | null;
context?: FloatingContext<RT>;
}
export declare function getDeepestNode<RT extends ReferenceType = ReferenceType>(nodes: Array<FloatingNodeType<RT>>, id: string | undefined): FloatingNodeType<RT> | undefined;
export declare function getDocument(node: Element | null): Document;
export declare function getFloatingFocusElement(floatingElement: HTMLElement | null | undefined): HTMLElement | null;
/** Gets cell index of an item's corner or -1 when index is -1. */
export declare function getGridCellIndexOfCorner(index: number, sizes: Dimensions[], cellMap: (number | undefined)[], cols: number, corner: 'tl' | 'tr' | 'bl' | 'br'): number;
/** Gets all cell indices that correspond to the specified indices */
export declare function getGridCellIndices(indices: (number | undefined)[], cellMap: (number | undefined)[]): number[];
export declare function getGridNavigatedIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, { event, orientation, loop, rtl, cols, disabledIndices, minIndex, maxIndex, prevIndex, stopEvent: stop, }: {
event: React.KeyboardEvent;
orientation: 'horizontal' | 'vertical' | 'both';
loop: boolean;
rtl: boolean;
cols: number;
disabledIndices: DisabledIndices | undefined;
minIndex: number;
maxIndex: number;
prevIndex: number;
stopEvent?: boolean;
}): number;
export declare function getMaxListIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, disabledIndices: DisabledIndices | undefined): number;
export declare function getMinListIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, disabledIndices: DisabledIndices | undefined): number;
export declare function getNextTabbable(referenceElement: Element | null): FocusableElement | null;
export declare function getNodeAncestors<RT extends ReferenceType = ReferenceType>(nodes: Array<FloatingNodeType<RT>>, id: string | undefined): FloatingNodeType<RT>[];
export declare function getNodeChildren<RT extends ReferenceType = ReferenceType>(nodes: Array<FloatingNodeType<RT>>, id: string | undefined, onlyOpenChildren?: boolean): Array<FloatingNodeType<RT>>;
export declare function getPlatform(): string;
export declare function getPreviousTabbable(referenceElement: Element | null): FocusableElement | null;
export declare const getTabbableOptions: () => {
readonly getShadowRoot: true;
readonly displayCheck: "none" | "full";
};
export declare function getTarget(event: Event): EventTarget | null;
export declare function getUserAgent(): string;
export declare function isAndroid(): boolean;
export declare function isDifferentGridRow(index: number, cols: number, prevRow: number): boolean;
export declare function isEventTargetWithin(event: Event, node: Node | null | undefined): boolean;
export declare function isIndexOutOfListBounds(listRef: React.MutableRefObject<Array<HTMLElement | null>>, index: number): boolean;
export declare function isJSDOM(): boolean;
export declare function isListIndexDisabled(listRef: React.MutableRefObject<Array<HTMLElement | null>>, index: number, disabledIndices?: DisabledIndices): boolean;
export declare function isMac(): boolean;
export declare function isMouseLikePointerType(pointerType: string | undefined, strict?: boolean): boolean;
export declare function isOutsideEvent(event: FocusEvent | React.FocusEvent, container?: Element): boolean;
export declare function isReactEvent(event: any): event is React.SyntheticEvent;
export declare function isRootElement(element: Element): boolean;
export declare function isSafari(): boolean;
export declare function isTypeableCombobox(element: Element | null): boolean;
export declare function isTypeableElement(element: unknown): boolean;
export declare function isVirtualClick(event: MouseEvent | PointerEvent): boolean;
export declare function isVirtualPointerEvent(event: PointerEvent): boolean;
export declare function matchesFocusVisible(element: Element | null): boolean;
declare type NarrowedElement<T> = T extends Element ? T : Element;
declare type OpenChangeReason = 'outside-press' | 'escape-key' | 'ancestor-scroll' | 'reference-press' | 'click' | 'hover' | 'focus' | 'focus-out' | 'list-navigation' | 'safe-polygon';
declare type ReferenceType = Element | VirtualElement;
export declare function stopEvent(event: Event | React.SyntheticEvent): void;
export declare function useEffectEvent<T extends AnyFunction>(callback?: T): T;
export declare function useLatestRef<T>(value: T): React.MutableRefObject<T>;
export { useModernLayoutEffect }
export { }

View File

@@ -0,0 +1,174 @@
/// <reference types="react" />
import { Dimensions } from '@floating-ui/react-dom';
import { FocusableElement } from 'tabbable';
import * as React from 'react';
import type { UseFloatingReturn } from '@floating-ui/react-dom';
import useModernLayoutEffect from 'use-isomorphic-layout-effect';
import type { VirtualElement } from '@floating-ui/react-dom';
export declare function activeElement(doc: Document): Element | null;
declare type AnyFunction = (...args: any[]) => any;
export declare function contains(parent?: Element | null, child?: Element | null): boolean;
declare interface ContextData {
openEvent?: Event;
floatingContext?: FloatingContext;
/** @deprecated use `onTypingChange` prop in `useTypeahead` */
typing?: boolean;
[key: string]: any;
}
/** For each cell index, gets the item index that occupies that cell */
export declare function createGridCellMap(sizes: Dimensions[], cols: number, dense: boolean): (number | undefined)[];
declare type DisabledIndices = Array<number> | ((index: number) => boolean);
export declare function disableFocusInside(container: HTMLElement): void;
export declare function enableFocusInside(container: HTMLElement): void;
declare interface ExtendedElements<RT> {
reference: ReferenceType | null;
floating: HTMLElement | null;
domReference: NarrowedElement<RT> | null;
}
declare interface ExtendedRefs<RT> {
reference: React.MutableRefObject<ReferenceType | null>;
floating: React.MutableRefObject<HTMLElement | null>;
domReference: React.MutableRefObject<NarrowedElement<RT> | null>;
setReference(node: RT | null): void;
setFloating(node: HTMLElement | null): void;
setPositionReference(node: ReferenceType | null): void;
}
export declare function findNonDisabledListIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, { startingIndex, decrement, disabledIndices, amount, }?: {
startingIndex?: number;
decrement?: boolean;
disabledIndices?: DisabledIndices;
amount?: number;
}): number;
declare type FloatingContext<RT extends ReferenceType = ReferenceType> = Omit<UseFloatingReturn<RT>, 'refs' | 'elements'> & {
open: boolean;
onOpenChange(open: boolean, event?: Event, reason?: OpenChangeReason): void;
events: FloatingEvents;
dataRef: React.MutableRefObject<ContextData>;
nodeId: string | undefined;
floatingId: string | undefined;
refs: ExtendedRefs<RT>;
elements: ExtendedElements<RT>;
};
declare interface FloatingEvents {
emit<T extends string>(event: T, data?: any): void;
on(event: string, handler: (data: any) => void): void;
off(event: string, handler: (data: any) => void): void;
}
declare interface FloatingNodeType<RT extends ReferenceType = ReferenceType> {
id: string | undefined;
parentId: string | null;
context?: FloatingContext<RT>;
}
export declare function getDeepestNode<RT extends ReferenceType = ReferenceType>(nodes: Array<FloatingNodeType<RT>>, id: string | undefined): FloatingNodeType<RT> | undefined;
export declare function getDocument(node: Element | null): Document;
export declare function getFloatingFocusElement(floatingElement: HTMLElement | null | undefined): HTMLElement | null;
/** Gets cell index of an item's corner or -1 when index is -1. */
export declare function getGridCellIndexOfCorner(index: number, sizes: Dimensions[], cellMap: (number | undefined)[], cols: number, corner: 'tl' | 'tr' | 'bl' | 'br'): number;
/** Gets all cell indices that correspond to the specified indices */
export declare function getGridCellIndices(indices: (number | undefined)[], cellMap: (number | undefined)[]): number[];
export declare function getGridNavigatedIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, { event, orientation, loop, rtl, cols, disabledIndices, minIndex, maxIndex, prevIndex, stopEvent: stop, }: {
event: React.KeyboardEvent;
orientation: 'horizontal' | 'vertical' | 'both';
loop: boolean;
rtl: boolean;
cols: number;
disabledIndices: DisabledIndices | undefined;
minIndex: number;
maxIndex: number;
prevIndex: number;
stopEvent?: boolean;
}): number;
export declare function getMaxListIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, disabledIndices: DisabledIndices | undefined): number;
export declare function getMinListIndex(listRef: React.MutableRefObject<Array<HTMLElement | null>>, disabledIndices: DisabledIndices | undefined): number;
export declare function getNextTabbable(referenceElement: Element | null): FocusableElement | null;
export declare function getNodeAncestors<RT extends ReferenceType = ReferenceType>(nodes: Array<FloatingNodeType<RT>>, id: string | undefined): FloatingNodeType<RT>[];
export declare function getNodeChildren<RT extends ReferenceType = ReferenceType>(nodes: Array<FloatingNodeType<RT>>, id: string | undefined, onlyOpenChildren?: boolean): Array<FloatingNodeType<RT>>;
export declare function getPlatform(): string;
export declare function getPreviousTabbable(referenceElement: Element | null): FocusableElement | null;
export declare const getTabbableOptions: () => {
readonly getShadowRoot: true;
readonly displayCheck: "none" | "full";
};
export declare function getTarget(event: Event): EventTarget | null;
export declare function getUserAgent(): string;
export declare function isAndroid(): boolean;
export declare function isDifferentGridRow(index: number, cols: number, prevRow: number): boolean;
export declare function isEventTargetWithin(event: Event, node: Node | null | undefined): boolean;
export declare function isIndexOutOfListBounds(listRef: React.MutableRefObject<Array<HTMLElement | null>>, index: number): boolean;
export declare function isJSDOM(): boolean;
export declare function isListIndexDisabled(listRef: React.MutableRefObject<Array<HTMLElement | null>>, index: number, disabledIndices?: DisabledIndices): boolean;
export declare function isMac(): boolean;
export declare function isMouseLikePointerType(pointerType: string | undefined, strict?: boolean): boolean;
export declare function isOutsideEvent(event: FocusEvent | React.FocusEvent, container?: Element): boolean;
export declare function isReactEvent(event: any): event is React.SyntheticEvent;
export declare function isRootElement(element: Element): boolean;
export declare function isSafari(): boolean;
export declare function isTypeableCombobox(element: Element | null): boolean;
export declare function isTypeableElement(element: unknown): boolean;
export declare function isVirtualClick(event: MouseEvent | PointerEvent): boolean;
export declare function isVirtualPointerEvent(event: PointerEvent): boolean;
export declare function matchesFocusVisible(element: Element | null): boolean;
declare type NarrowedElement<T> = T extends Element ? T : Element;
declare type OpenChangeReason = 'outside-press' | 'escape-key' | 'ancestor-scroll' | 'reference-press' | 'click' | 'hover' | 'focus' | 'focus-out' | 'list-navigation' | 'safe-polygon';
declare type ReferenceType = Element | VirtualElement;
export declare function stopEvent(event: Event | React.SyntheticEvent): void;
export declare function useEffectEvent<T extends AnyFunction>(callback?: T): T;
export declare function useLatestRef<T>(value: T): React.MutableRefObject<T>;
export { useModernLayoutEffect }
export { }

View File

@@ -0,0 +1,537 @@
import { isShadowRoot, isHTMLElement } from '@floating-ui/utils/dom';
import * as React from 'react';
import { useLayoutEffect } from 'react';
import { floor } from '@floating-ui/utils';
import { tabbable } from 'tabbable';
// Avoid Chrome DevTools blue warning.
function getPlatform() {
const uaData = navigator.userAgentData;
if (uaData != null && uaData.platform) {
return uaData.platform;
}
return navigator.platform;
}
function getUserAgent() {
const uaData = navigator.userAgentData;
if (uaData && Array.isArray(uaData.brands)) {
return uaData.brands.map(_ref => {
let {
brand,
version
} = _ref;
return brand + "/" + version;
}).join(' ');
}
return navigator.userAgent;
}
function isSafari() {
// Chrome DevTools does not complain about navigator.vendor
return /apple/i.test(navigator.vendor);
}
function isAndroid() {
const re = /android/i;
return re.test(getPlatform()) || re.test(getUserAgent());
}
function isMac() {
return getPlatform().toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
}
function isJSDOM() {
return getUserAgent().includes('jsdom/');
}
const FOCUSABLE_ATTRIBUTE = 'data-floating-ui-focusable';
const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
const ARROW_LEFT = 'ArrowLeft';
const ARROW_RIGHT = 'ArrowRight';
const ARROW_UP = 'ArrowUp';
const ARROW_DOWN = 'ArrowDown';
function activeElement(doc) {
let activeElement = doc.activeElement;
while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
var _activeElement;
activeElement = activeElement.shadowRoot.activeElement;
}
return activeElement;
}
function contains(parent, child) {
if (!parent || !child) {
return false;
}
const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
// First, attempt with faster native method
if (parent.contains(child)) {
return true;
}
// then fallback to custom implementation with Shadow DOM support
if (rootNode && isShadowRoot(rootNode)) {
let next = child;
while (next) {
if (parent === next) {
return true;
}
// @ts-ignore
next = next.parentNode || next.host;
}
}
// Give up, the result is false
return false;
}
function getTarget(event) {
if ('composedPath' in event) {
return event.composedPath()[0];
}
// TS thinks `event` is of type never as it assumes all browsers support
// `composedPath()`, but browsers without shadow DOM don't.
return event.target;
}
function isEventTargetWithin(event, node) {
if (node == null) {
return false;
}
if ('composedPath' in event) {
return event.composedPath().includes(node);
}
// TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
const e = event;
return e.target != null && node.contains(e.target);
}
function isRootElement(element) {
return element.matches('html,body');
}
function getDocument(node) {
return (node == null ? void 0 : node.ownerDocument) || document;
}
function isTypeableElement(element) {
return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
}
function isTypeableCombobox(element) {
if (!element) return false;
return element.getAttribute('role') === 'combobox' && isTypeableElement(element);
}
function matchesFocusVisible(element) {
// We don't want to block focus from working with `visibleOnly`
// (JSDOM doesn't match `:focus-visible` when the element has `:focus`)
if (!element || isJSDOM()) return true;
try {
return element.matches(':focus-visible');
} catch (_e) {
return true;
}
}
function getFloatingFocusElement(floatingElement) {
if (!floatingElement) {
return null;
}
// Try to find the element that has `{...getFloatingProps()}` spread on it.
// This indicates the floating element is acting as a positioning wrapper, and
// so focus should be managed on the child element with the event handlers and
// aria props.
return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
}
function getNodeChildren(nodes, id, onlyOpenChildren) {
if (onlyOpenChildren === void 0) {
onlyOpenChildren = true;
}
const directChildren = nodes.filter(node => {
var _node$context;
return node.parentId === id && (!onlyOpenChildren || ((_node$context = node.context) == null ? void 0 : _node$context.open));
});
return directChildren.flatMap(child => [child, ...getNodeChildren(nodes, child.id, onlyOpenChildren)]);
}
function getDeepestNode(nodes, id) {
let deepestNodeId;
let maxDepth = -1;
function findDeepest(nodeId, depth) {
if (depth > maxDepth) {
deepestNodeId = nodeId;
maxDepth = depth;
}
const children = getNodeChildren(nodes, nodeId);
children.forEach(child => {
findDeepest(child.id, depth + 1);
});
}
findDeepest(id, 0);
return nodes.find(node => node.id === deepestNodeId);
}
function getNodeAncestors(nodes, id) {
var _nodes$find;
let allAncestors = [];
let currentParentId = (_nodes$find = nodes.find(node => node.id === id)) == null ? void 0 : _nodes$find.parentId;
while (currentParentId) {
const currentNode = nodes.find(node => node.id === currentParentId);
currentParentId = currentNode == null ? void 0 : currentNode.parentId;
if (currentNode) {
allAncestors = allAncestors.concat(currentNode);
}
}
return allAncestors;
}
function stopEvent(event) {
event.preventDefault();
event.stopPropagation();
}
function isReactEvent(event) {
return 'nativeEvent' in event;
}
// License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts
function isVirtualClick(event) {
// FIXME: Firefox is now emitting a deprecation warning for `mozInputSource`.
// Try to find a workaround for this. `react-aria` source still has the check.
if (event.mozInputSource === 0 && event.isTrusted) {
return true;
}
if (isAndroid() && event.pointerType) {
return event.type === 'click' && event.buttons === 1;
}
return event.detail === 0 && !event.pointerType;
}
function isVirtualPointerEvent(event) {
if (isJSDOM()) return false;
return !isAndroid() && event.width === 0 && event.height === 0 || isAndroid() && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse' ||
// iOS VoiceOver returns 0.333• for width/height.
event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'touch';
}
function isMouseLikePointerType(pointerType, strict) {
// On some Linux machines with Chromium, mouse inputs return a `pointerType`
// of "pen": https://github.com/floating-ui/floating-ui/issues/2015
const values = ['mouse', 'pen'];
if (!strict) {
values.push('', undefined);
}
return values.includes(pointerType);
}
var isClient = typeof document !== 'undefined';
var noop = function noop() {};
var index = isClient ? useLayoutEffect : noop;
// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
const SafeReact = {
...React
};
function useLatestRef(value) {
const ref = React.useRef(value);
index(() => {
ref.current = value;
});
return ref;
}
const useInsertionEffect = SafeReact.useInsertionEffect;
const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
function useEffectEvent(callback) {
const ref = React.useRef(() => {
if (process.env.NODE_ENV !== "production") {
throw new Error('Cannot call an event handler while rendering.');
}
});
useSafeInsertionEffect(() => {
ref.current = callback;
});
return React.useCallback(function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return ref.current == null ? void 0 : ref.current(...args);
}, []);
}
function isDifferentGridRow(index, cols, prevRow) {
return Math.floor(index / cols) !== prevRow;
}
function isIndexOutOfListBounds(listRef, index) {
return index < 0 || index >= listRef.current.length;
}
function getMinListIndex(listRef, disabledIndices) {
return findNonDisabledListIndex(listRef, {
disabledIndices
});
}
function getMaxListIndex(listRef, disabledIndices) {
return findNonDisabledListIndex(listRef, {
decrement: true,
startingIndex: listRef.current.length,
disabledIndices
});
}
function findNonDisabledListIndex(listRef, _temp) {
let {
startingIndex = -1,
decrement = false,
disabledIndices,
amount = 1
} = _temp === void 0 ? {} : _temp;
let index = startingIndex;
do {
index += decrement ? -amount : amount;
} while (index >= 0 && index <= listRef.current.length - 1 && isListIndexDisabled(listRef, index, disabledIndices));
return index;
}
function getGridNavigatedIndex(listRef, _ref) {
let {
event,
orientation,
loop,
rtl,
cols,
disabledIndices,
minIndex,
maxIndex,
prevIndex,
stopEvent: stop = false
} = _ref;
let nextIndex = prevIndex;
if (event.key === ARROW_UP) {
stop && stopEvent(event);
if (prevIndex === -1) {
nextIndex = maxIndex;
} else {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: nextIndex,
amount: cols,
decrement: true,
disabledIndices
});
if (loop && (prevIndex - cols < minIndex || nextIndex < 0)) {
const col = prevIndex % cols;
const maxCol = maxIndex % cols;
const offset = maxIndex - (maxCol - col);
if (maxCol === col) {
nextIndex = maxIndex;
} else {
nextIndex = maxCol > col ? offset : offset - cols;
}
}
}
if (isIndexOutOfListBounds(listRef, nextIndex)) {
nextIndex = prevIndex;
}
}
if (event.key === ARROW_DOWN) {
stop && stopEvent(event);
if (prevIndex === -1) {
nextIndex = minIndex;
} else {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex,
amount: cols,
disabledIndices
});
if (loop && prevIndex + cols > maxIndex) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex % cols - cols,
amount: cols,
disabledIndices
});
}
}
if (isIndexOutOfListBounds(listRef, nextIndex)) {
nextIndex = prevIndex;
}
}
// Remains on the same row/column.
if (orientation === 'both') {
const prevRow = floor(prevIndex / cols);
if (event.key === (rtl ? ARROW_LEFT : ARROW_RIGHT)) {
stop && stopEvent(event);
if (prevIndex % cols !== cols - 1) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex,
disabledIndices
});
if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex - prevIndex % cols - 1,
disabledIndices
});
}
} else if (loop) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex - prevIndex % cols - 1,
disabledIndices
});
}
if (isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = prevIndex;
}
}
if (event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT)) {
stop && stopEvent(event);
if (prevIndex % cols !== 0) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex,
decrement: true,
disabledIndices
});
if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex + (cols - prevIndex % cols),
decrement: true,
disabledIndices
});
}
} else if (loop) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex + (cols - prevIndex % cols),
decrement: true,
disabledIndices
});
}
if (isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = prevIndex;
}
}
const lastRow = floor(maxIndex / cols) === prevRow;
if (isIndexOutOfListBounds(listRef, nextIndex)) {
if (loop && lastRow) {
nextIndex = event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT) ? maxIndex : findNonDisabledListIndex(listRef, {
startingIndex: prevIndex - prevIndex % cols - 1,
disabledIndices
});
} else {
nextIndex = prevIndex;
}
}
}
return nextIndex;
}
/** For each cell index, gets the item index that occupies that cell */
function createGridCellMap(sizes, cols, dense) {
const cellMap = [];
let startIndex = 0;
sizes.forEach((_ref2, index) => {
let {
width,
height
} = _ref2;
if (width > cols) {
if (process.env.NODE_ENV !== "production") {
throw new Error("[Floating UI]: Invalid grid - item width at index " + index + " is greater than grid columns");
}
}
let itemPlaced = false;
if (dense) {
startIndex = 0;
}
while (!itemPlaced) {
const targetCells = [];
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
targetCells.push(startIndex + i + j * cols);
}
}
if (startIndex % cols + width <= cols && targetCells.every(cell => cellMap[cell] == null)) {
targetCells.forEach(cell => {
cellMap[cell] = index;
});
itemPlaced = true;
} else {
startIndex++;
}
}
});
// convert into a non-sparse array
return [...cellMap];
}
/** Gets cell index of an item's corner or -1 when index is -1. */
function getGridCellIndexOfCorner(index, sizes, cellMap, cols, corner) {
if (index === -1) return -1;
const firstCellIndex = cellMap.indexOf(index);
const sizeItem = sizes[index];
switch (corner) {
case 'tl':
return firstCellIndex;
case 'tr':
if (!sizeItem) {
return firstCellIndex;
}
return firstCellIndex + sizeItem.width - 1;
case 'bl':
if (!sizeItem) {
return firstCellIndex;
}
return firstCellIndex + (sizeItem.height - 1) * cols;
case 'br':
return cellMap.lastIndexOf(index);
}
}
/** Gets all cell indices that correspond to the specified indices */
function getGridCellIndices(indices, cellMap) {
return cellMap.flatMap((index, cellIndex) => indices.includes(index) ? [cellIndex] : []);
}
function isListIndexDisabled(listRef, index, disabledIndices) {
if (typeof disabledIndices === 'function') {
return disabledIndices(index);
} else if (disabledIndices) {
return disabledIndices.includes(index);
}
const element = listRef.current[index];
return element == null || element.hasAttribute('disabled') || element.getAttribute('aria-disabled') === 'true';
}
const getTabbableOptions = () => ({
getShadowRoot: true,
displayCheck:
// JSDOM does not support the `tabbable` library. To solve this we can
// check if `ResizeObserver` is a real function (not polyfilled), which
// determines if the current environment is JSDOM-like.
typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
});
function getTabbableIn(container, dir) {
const list = tabbable(container, getTabbableOptions());
const len = list.length;
if (len === 0) return;
const active = activeElement(getDocument(container));
const index = list.indexOf(active);
const nextIndex = index === -1 ? dir === 1 ? 0 : len - 1 : index + dir;
return list[nextIndex];
}
function getNextTabbable(referenceElement) {
return getTabbableIn(getDocument(referenceElement).body, 1) || referenceElement;
}
function getPreviousTabbable(referenceElement) {
return getTabbableIn(getDocument(referenceElement).body, -1) || referenceElement;
}
function isOutsideEvent(event, container) {
const containerElement = container || event.currentTarget;
const relatedTarget = event.relatedTarget;
return !relatedTarget || !contains(containerElement, relatedTarget);
}
function disableFocusInside(container) {
const tabbableElements = tabbable(container, getTabbableOptions());
tabbableElements.forEach(element => {
element.dataset.tabindex = element.getAttribute('tabindex') || '';
element.setAttribute('tabindex', '-1');
});
}
function enableFocusInside(container) {
const elements = container.querySelectorAll('[data-tabindex]');
elements.forEach(element => {
const tabindex = element.dataset.tabindex;
delete element.dataset.tabindex;
if (tabindex) {
element.setAttribute('tabindex', tabindex);
} else {
element.removeAttribute('tabindex');
}
});
}
export { activeElement, contains, createGridCellMap, disableFocusInside, enableFocusInside, findNonDisabledListIndex, getDeepestNode, getDocument, getFloatingFocusElement, getGridCellIndexOfCorner, getGridCellIndices, getGridNavigatedIndex, getMaxListIndex, getMinListIndex, getNextTabbable, getNodeAncestors, getNodeChildren, getPlatform, getPreviousTabbable, getTabbableOptions, getTarget, getUserAgent, isAndroid, isDifferentGridRow, isEventTargetWithin, isIndexOutOfListBounds, isJSDOM, isListIndexDisabled, isMac, isMouseLikePointerType, isOutsideEvent, isReactEvent, isRootElement, isSafari, isTypeableCombobox, isTypeableElement, isVirtualClick, isVirtualPointerEvent, matchesFocusVisible, stopEvent, useEffectEvent, useLatestRef, index as useModernLayoutEffect };

View File

@@ -0,0 +1,537 @@
import { isShadowRoot, isHTMLElement } from '@floating-ui/utils/dom';
import * as React from 'react';
import { useLayoutEffect } from 'react';
import { floor } from '@floating-ui/utils';
import { tabbable } from 'tabbable';
// Avoid Chrome DevTools blue warning.
function getPlatform() {
const uaData = navigator.userAgentData;
if (uaData != null && uaData.platform) {
return uaData.platform;
}
return navigator.platform;
}
function getUserAgent() {
const uaData = navigator.userAgentData;
if (uaData && Array.isArray(uaData.brands)) {
return uaData.brands.map(_ref => {
let {
brand,
version
} = _ref;
return brand + "/" + version;
}).join(' ');
}
return navigator.userAgent;
}
function isSafari() {
// Chrome DevTools does not complain about navigator.vendor
return /apple/i.test(navigator.vendor);
}
function isAndroid() {
const re = /android/i;
return re.test(getPlatform()) || re.test(getUserAgent());
}
function isMac() {
return getPlatform().toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
}
function isJSDOM() {
return getUserAgent().includes('jsdom/');
}
const FOCUSABLE_ATTRIBUTE = 'data-floating-ui-focusable';
const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled])," + "[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
const ARROW_LEFT = 'ArrowLeft';
const ARROW_RIGHT = 'ArrowRight';
const ARROW_UP = 'ArrowUp';
const ARROW_DOWN = 'ArrowDown';
function activeElement(doc) {
let activeElement = doc.activeElement;
while (((_activeElement = activeElement) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
var _activeElement;
activeElement = activeElement.shadowRoot.activeElement;
}
return activeElement;
}
function contains(parent, child) {
if (!parent || !child) {
return false;
}
const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
// First, attempt with faster native method
if (parent.contains(child)) {
return true;
}
// then fallback to custom implementation with Shadow DOM support
if (rootNode && isShadowRoot(rootNode)) {
let next = child;
while (next) {
if (parent === next) {
return true;
}
// @ts-ignore
next = next.parentNode || next.host;
}
}
// Give up, the result is false
return false;
}
function getTarget(event) {
if ('composedPath' in event) {
return event.composedPath()[0];
}
// TS thinks `event` is of type never as it assumes all browsers support
// `composedPath()`, but browsers without shadow DOM don't.
return event.target;
}
function isEventTargetWithin(event, node) {
if (node == null) {
return false;
}
if ('composedPath' in event) {
return event.composedPath().includes(node);
}
// TS thinks `event` is of type never as it assumes all browsers support composedPath, but browsers without shadow dom don't
const e = event;
return e.target != null && node.contains(e.target);
}
function isRootElement(element) {
return element.matches('html,body');
}
function getDocument(node) {
return (node == null ? void 0 : node.ownerDocument) || document;
}
function isTypeableElement(element) {
return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
}
function isTypeableCombobox(element) {
if (!element) return false;
return element.getAttribute('role') === 'combobox' && isTypeableElement(element);
}
function matchesFocusVisible(element) {
// We don't want to block focus from working with `visibleOnly`
// (JSDOM doesn't match `:focus-visible` when the element has `:focus`)
if (!element || isJSDOM()) return true;
try {
return element.matches(':focus-visible');
} catch (_e) {
return true;
}
}
function getFloatingFocusElement(floatingElement) {
if (!floatingElement) {
return null;
}
// Try to find the element that has `{...getFloatingProps()}` spread on it.
// This indicates the floating element is acting as a positioning wrapper, and
// so focus should be managed on the child element with the event handlers and
// aria props.
return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE + "]") || floatingElement;
}
function getNodeChildren(nodes, id, onlyOpenChildren) {
if (onlyOpenChildren === void 0) {
onlyOpenChildren = true;
}
const directChildren = nodes.filter(node => {
var _node$context;
return node.parentId === id && (!onlyOpenChildren || ((_node$context = node.context) == null ? void 0 : _node$context.open));
});
return directChildren.flatMap(child => [child, ...getNodeChildren(nodes, child.id, onlyOpenChildren)]);
}
function getDeepestNode(nodes, id) {
let deepestNodeId;
let maxDepth = -1;
function findDeepest(nodeId, depth) {
if (depth > maxDepth) {
deepestNodeId = nodeId;
maxDepth = depth;
}
const children = getNodeChildren(nodes, nodeId);
children.forEach(child => {
findDeepest(child.id, depth + 1);
});
}
findDeepest(id, 0);
return nodes.find(node => node.id === deepestNodeId);
}
function getNodeAncestors(nodes, id) {
var _nodes$find;
let allAncestors = [];
let currentParentId = (_nodes$find = nodes.find(node => node.id === id)) == null ? void 0 : _nodes$find.parentId;
while (currentParentId) {
const currentNode = nodes.find(node => node.id === currentParentId);
currentParentId = currentNode == null ? void 0 : currentNode.parentId;
if (currentNode) {
allAncestors = allAncestors.concat(currentNode);
}
}
return allAncestors;
}
function stopEvent(event) {
event.preventDefault();
event.stopPropagation();
}
function isReactEvent(event) {
return 'nativeEvent' in event;
}
// License: https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/@react-aria/utils/src/isVirtualEvent.ts
function isVirtualClick(event) {
// FIXME: Firefox is now emitting a deprecation warning for `mozInputSource`.
// Try to find a workaround for this. `react-aria` source still has the check.
if (event.mozInputSource === 0 && event.isTrusted) {
return true;
}
if (isAndroid() && event.pointerType) {
return event.type === 'click' && event.buttons === 1;
}
return event.detail === 0 && !event.pointerType;
}
function isVirtualPointerEvent(event) {
if (isJSDOM()) return false;
return !isAndroid() && event.width === 0 && event.height === 0 || isAndroid() && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse' ||
// iOS VoiceOver returns 0.333• for width/height.
event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'touch';
}
function isMouseLikePointerType(pointerType, strict) {
// On some Linux machines with Chromium, mouse inputs return a `pointerType`
// of "pen": https://github.com/floating-ui/floating-ui/issues/2015
const values = ['mouse', 'pen'];
if (!strict) {
values.push('', undefined);
}
return values.includes(pointerType);
}
var isClient = typeof document !== 'undefined';
var noop = function noop() {};
var index = isClient ? useLayoutEffect : noop;
// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
const SafeReact = {
...React
};
function useLatestRef(value) {
const ref = React.useRef(value);
index(() => {
ref.current = value;
});
return ref;
}
const useInsertionEffect = SafeReact.useInsertionEffect;
const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
function useEffectEvent(callback) {
const ref = React.useRef(() => {
if (process.env.NODE_ENV !== "production") {
throw new Error('Cannot call an event handler while rendering.');
}
});
useSafeInsertionEffect(() => {
ref.current = callback;
});
return React.useCallback(function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return ref.current == null ? void 0 : ref.current(...args);
}, []);
}
function isDifferentGridRow(index, cols, prevRow) {
return Math.floor(index / cols) !== prevRow;
}
function isIndexOutOfListBounds(listRef, index) {
return index < 0 || index >= listRef.current.length;
}
function getMinListIndex(listRef, disabledIndices) {
return findNonDisabledListIndex(listRef, {
disabledIndices
});
}
function getMaxListIndex(listRef, disabledIndices) {
return findNonDisabledListIndex(listRef, {
decrement: true,
startingIndex: listRef.current.length,
disabledIndices
});
}
function findNonDisabledListIndex(listRef, _temp) {
let {
startingIndex = -1,
decrement = false,
disabledIndices,
amount = 1
} = _temp === void 0 ? {} : _temp;
let index = startingIndex;
do {
index += decrement ? -amount : amount;
} while (index >= 0 && index <= listRef.current.length - 1 && isListIndexDisabled(listRef, index, disabledIndices));
return index;
}
function getGridNavigatedIndex(listRef, _ref) {
let {
event,
orientation,
loop,
rtl,
cols,
disabledIndices,
minIndex,
maxIndex,
prevIndex,
stopEvent: stop = false
} = _ref;
let nextIndex = prevIndex;
if (event.key === ARROW_UP) {
stop && stopEvent(event);
if (prevIndex === -1) {
nextIndex = maxIndex;
} else {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: nextIndex,
amount: cols,
decrement: true,
disabledIndices
});
if (loop && (prevIndex - cols < minIndex || nextIndex < 0)) {
const col = prevIndex % cols;
const maxCol = maxIndex % cols;
const offset = maxIndex - (maxCol - col);
if (maxCol === col) {
nextIndex = maxIndex;
} else {
nextIndex = maxCol > col ? offset : offset - cols;
}
}
}
if (isIndexOutOfListBounds(listRef, nextIndex)) {
nextIndex = prevIndex;
}
}
if (event.key === ARROW_DOWN) {
stop && stopEvent(event);
if (prevIndex === -1) {
nextIndex = minIndex;
} else {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex,
amount: cols,
disabledIndices
});
if (loop && prevIndex + cols > maxIndex) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex % cols - cols,
amount: cols,
disabledIndices
});
}
}
if (isIndexOutOfListBounds(listRef, nextIndex)) {
nextIndex = prevIndex;
}
}
// Remains on the same row/column.
if (orientation === 'both') {
const prevRow = floor(prevIndex / cols);
if (event.key === (rtl ? ARROW_LEFT : ARROW_RIGHT)) {
stop && stopEvent(event);
if (prevIndex % cols !== cols - 1) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex,
disabledIndices
});
if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex - prevIndex % cols - 1,
disabledIndices
});
}
} else if (loop) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex - prevIndex % cols - 1,
disabledIndices
});
}
if (isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = prevIndex;
}
}
if (event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT)) {
stop && stopEvent(event);
if (prevIndex % cols !== 0) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex,
decrement: true,
disabledIndices
});
if (loop && isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex + (cols - prevIndex % cols),
decrement: true,
disabledIndices
});
}
} else if (loop) {
nextIndex = findNonDisabledListIndex(listRef, {
startingIndex: prevIndex + (cols - prevIndex % cols),
decrement: true,
disabledIndices
});
}
if (isDifferentGridRow(nextIndex, cols, prevRow)) {
nextIndex = prevIndex;
}
}
const lastRow = floor(maxIndex / cols) === prevRow;
if (isIndexOutOfListBounds(listRef, nextIndex)) {
if (loop && lastRow) {
nextIndex = event.key === (rtl ? ARROW_RIGHT : ARROW_LEFT) ? maxIndex : findNonDisabledListIndex(listRef, {
startingIndex: prevIndex - prevIndex % cols - 1,
disabledIndices
});
} else {
nextIndex = prevIndex;
}
}
}
return nextIndex;
}
/** For each cell index, gets the item index that occupies that cell */
function createGridCellMap(sizes, cols, dense) {
const cellMap = [];
let startIndex = 0;
sizes.forEach((_ref2, index) => {
let {
width,
height
} = _ref2;
if (width > cols) {
if (process.env.NODE_ENV !== "production") {
throw new Error("[Floating UI]: Invalid grid - item width at index " + index + " is greater than grid columns");
}
}
let itemPlaced = false;
if (dense) {
startIndex = 0;
}
while (!itemPlaced) {
const targetCells = [];
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
targetCells.push(startIndex + i + j * cols);
}
}
if (startIndex % cols + width <= cols && targetCells.every(cell => cellMap[cell] == null)) {
targetCells.forEach(cell => {
cellMap[cell] = index;
});
itemPlaced = true;
} else {
startIndex++;
}
}
});
// convert into a non-sparse array
return [...cellMap];
}
/** Gets cell index of an item's corner or -1 when index is -1. */
function getGridCellIndexOfCorner(index, sizes, cellMap, cols, corner) {
if (index === -1) return -1;
const firstCellIndex = cellMap.indexOf(index);
const sizeItem = sizes[index];
switch (corner) {
case 'tl':
return firstCellIndex;
case 'tr':
if (!sizeItem) {
return firstCellIndex;
}
return firstCellIndex + sizeItem.width - 1;
case 'bl':
if (!sizeItem) {
return firstCellIndex;
}
return firstCellIndex + (sizeItem.height - 1) * cols;
case 'br':
return cellMap.lastIndexOf(index);
}
}
/** Gets all cell indices that correspond to the specified indices */
function getGridCellIndices(indices, cellMap) {
return cellMap.flatMap((index, cellIndex) => indices.includes(index) ? [cellIndex] : []);
}
function isListIndexDisabled(listRef, index, disabledIndices) {
if (typeof disabledIndices === 'function') {
return disabledIndices(index);
} else if (disabledIndices) {
return disabledIndices.includes(index);
}
const element = listRef.current[index];
return element == null || element.hasAttribute('disabled') || element.getAttribute('aria-disabled') === 'true';
}
const getTabbableOptions = () => ({
getShadowRoot: true,
displayCheck:
// JSDOM does not support the `tabbable` library. To solve this we can
// check if `ResizeObserver` is a real function (not polyfilled), which
// determines if the current environment is JSDOM-like.
typeof ResizeObserver === 'function' && ResizeObserver.toString().includes('[native code]') ? 'full' : 'none'
});
function getTabbableIn(container, dir) {
const list = tabbable(container, getTabbableOptions());
const len = list.length;
if (len === 0) return;
const active = activeElement(getDocument(container));
const index = list.indexOf(active);
const nextIndex = index === -1 ? dir === 1 ? 0 : len - 1 : index + dir;
return list[nextIndex];
}
function getNextTabbable(referenceElement) {
return getTabbableIn(getDocument(referenceElement).body, 1) || referenceElement;
}
function getPreviousTabbable(referenceElement) {
return getTabbableIn(getDocument(referenceElement).body, -1) || referenceElement;
}
function isOutsideEvent(event, container) {
const containerElement = container || event.currentTarget;
const relatedTarget = event.relatedTarget;
return !relatedTarget || !contains(containerElement, relatedTarget);
}
function disableFocusInside(container) {
const tabbableElements = tabbable(container, getTabbableOptions());
tabbableElements.forEach(element => {
element.dataset.tabindex = element.getAttribute('tabindex') || '';
element.setAttribute('tabindex', '-1');
});
}
function enableFocusInside(container) {
const elements = container.querySelectorAll('[data-tabindex]');
elements.forEach(element => {
const tabindex = element.dataset.tabindex;
delete element.dataset.tabindex;
if (tabindex) {
element.setAttribute('tabindex', tabindex);
} else {
element.removeAttribute('tabindex');
}
});
}
export { activeElement, contains, createGridCellMap, disableFocusInside, enableFocusInside, findNonDisabledListIndex, getDeepestNode, getDocument, getFloatingFocusElement, getGridCellIndexOfCorner, getGridCellIndices, getGridNavigatedIndex, getMaxListIndex, getMinListIndex, getNextTabbable, getNodeAncestors, getNodeChildren, getPlatform, getPreviousTabbable, getTabbableOptions, getTarget, getUserAgent, isAndroid, isDifferentGridRow, isEventTargetWithin, isIndexOutOfListBounds, isJSDOM, isListIndexDisabled, isMac, isMouseLikePointerType, isOutsideEvent, isReactEvent, isRootElement, isSafari, isTypeableCombobox, isTypeableElement, isVirtualClick, isVirtualPointerEvent, matchesFocusVisible, stopEvent, useEffectEvent, useLatestRef, index as useModernLayoutEffect };

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long