Initial commit
This commit is contained in:
13
node_modules/@radix-ui/react-roving-focus/README.md
generated
vendored
Normal file
13
node_modules/@radix-ui/react-roving-focus/README.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# `react-roving-focus`
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ yarn add @radix-ui/react-roving-focus
|
||||
# or
|
||||
$ npm install @radix-ui/react-roving-focus
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This is an internal utility, not intended for public usage.
|
||||
45
node_modules/@radix-ui/react-roving-focus/dist/index.d.mts
generated
vendored
Normal file
45
node_modules/@radix-ui/react-roving-focus/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import * as _radix_ui_react_context from '@radix-ui/react-context';
|
||||
import * as React from 'react';
|
||||
import { Primitive } from '@radix-ui/react-primitive';
|
||||
|
||||
declare const createRovingFocusGroupScope: _radix_ui_react_context.CreateScope;
|
||||
type Orientation = React.AriaAttributes['aria-orientation'];
|
||||
type Direction = 'ltr' | 'rtl';
|
||||
interface RovingFocusGroupOptions {
|
||||
/**
|
||||
* The orientation of the group.
|
||||
* Mainly so arrow navigation is done accordingly (left & right vs. up & down)
|
||||
*/
|
||||
orientation?: Orientation;
|
||||
/**
|
||||
* The direction of navigation between items.
|
||||
*/
|
||||
dir?: Direction;
|
||||
/**
|
||||
* Whether keyboard navigation should loop around
|
||||
* @defaultValue false
|
||||
*/
|
||||
loop?: boolean;
|
||||
}
|
||||
interface RovingFocusGroupProps extends RovingFocusGroupImplProps {
|
||||
}
|
||||
declare const RovingFocusGroup: React.ForwardRefExoticComponent<RovingFocusGroupProps & React.RefAttributes<HTMLDivElement>>;
|
||||
type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
|
||||
interface RovingFocusGroupImplProps extends Omit<PrimitiveDivProps, 'dir'>, RovingFocusGroupOptions {
|
||||
currentTabStopId?: string | null;
|
||||
defaultCurrentTabStopId?: string;
|
||||
onCurrentTabStopIdChange?: (tabStopId: string | null) => void;
|
||||
onEntryFocus?: (event: Event) => void;
|
||||
preventScrollOnEntryFocus?: boolean;
|
||||
}
|
||||
type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
|
||||
interface RovingFocusItemProps extends PrimitiveSpanProps {
|
||||
tabStopId?: string;
|
||||
focusable?: boolean;
|
||||
active?: boolean;
|
||||
}
|
||||
declare const RovingFocusGroupItem: React.ForwardRefExoticComponent<RovingFocusItemProps & React.RefAttributes<HTMLSpanElement>>;
|
||||
declare const Root: React.ForwardRefExoticComponent<RovingFocusGroupProps & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const Item: React.ForwardRefExoticComponent<RovingFocusItemProps & React.RefAttributes<HTMLSpanElement>>;
|
||||
|
||||
export { Item, Root, RovingFocusGroup, RovingFocusGroupItem, type RovingFocusGroupProps, type RovingFocusItemProps, createRovingFocusGroupScope };
|
||||
45
node_modules/@radix-ui/react-roving-focus/dist/index.d.ts
generated
vendored
Normal file
45
node_modules/@radix-ui/react-roving-focus/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
import * as _radix_ui_react_context from '@radix-ui/react-context';
|
||||
import * as React from 'react';
|
||||
import { Primitive } from '@radix-ui/react-primitive';
|
||||
|
||||
declare const createRovingFocusGroupScope: _radix_ui_react_context.CreateScope;
|
||||
type Orientation = React.AriaAttributes['aria-orientation'];
|
||||
type Direction = 'ltr' | 'rtl';
|
||||
interface RovingFocusGroupOptions {
|
||||
/**
|
||||
* The orientation of the group.
|
||||
* Mainly so arrow navigation is done accordingly (left & right vs. up & down)
|
||||
*/
|
||||
orientation?: Orientation;
|
||||
/**
|
||||
* The direction of navigation between items.
|
||||
*/
|
||||
dir?: Direction;
|
||||
/**
|
||||
* Whether keyboard navigation should loop around
|
||||
* @defaultValue false
|
||||
*/
|
||||
loop?: boolean;
|
||||
}
|
||||
interface RovingFocusGroupProps extends RovingFocusGroupImplProps {
|
||||
}
|
||||
declare const RovingFocusGroup: React.ForwardRefExoticComponent<RovingFocusGroupProps & React.RefAttributes<HTMLDivElement>>;
|
||||
type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
|
||||
interface RovingFocusGroupImplProps extends Omit<PrimitiveDivProps, 'dir'>, RovingFocusGroupOptions {
|
||||
currentTabStopId?: string | null;
|
||||
defaultCurrentTabStopId?: string;
|
||||
onCurrentTabStopIdChange?: (tabStopId: string | null) => void;
|
||||
onEntryFocus?: (event: Event) => void;
|
||||
preventScrollOnEntryFocus?: boolean;
|
||||
}
|
||||
type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
|
||||
interface RovingFocusItemProps extends PrimitiveSpanProps {
|
||||
tabStopId?: string;
|
||||
focusable?: boolean;
|
||||
active?: boolean;
|
||||
}
|
||||
declare const RovingFocusGroupItem: React.ForwardRefExoticComponent<RovingFocusItemProps & React.RefAttributes<HTMLSpanElement>>;
|
||||
declare const Root: React.ForwardRefExoticComponent<RovingFocusGroupProps & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const Item: React.ForwardRefExoticComponent<RovingFocusItemProps & React.RefAttributes<HTMLSpanElement>>;
|
||||
|
||||
export { Item, Root, RovingFocusGroup, RovingFocusGroupItem, type RovingFocusGroupProps, type RovingFocusItemProps, createRovingFocusGroupScope };
|
||||
260
node_modules/@radix-ui/react-roving-focus/dist/index.js
generated
vendored
Normal file
260
node_modules/@radix-ui/react-roving-focus/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
"use strict";
|
||||
"use client";
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||
// If the importer is in node compatibility mode or this is not an ESM
|
||||
// file that has been converted to a CommonJS file using a Babel-
|
||||
// compatible transform (i.e. "__esModule" has not been set), then set
|
||||
// "default" to the CommonJS "module.exports" for node compatibility.
|
||||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||
mod
|
||||
));
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// packages/react/roving-focus/src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
Item: () => Item,
|
||||
Root: () => Root,
|
||||
RovingFocusGroup: () => RovingFocusGroup,
|
||||
RovingFocusGroupItem: () => RovingFocusGroupItem,
|
||||
createRovingFocusGroupScope: () => createRovingFocusGroupScope
|
||||
});
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
|
||||
// packages/react/roving-focus/src/roving-focus-group.tsx
|
||||
var React = __toESM(require("react"));
|
||||
var import_primitive = require("@radix-ui/primitive");
|
||||
var import_react_collection = require("@radix-ui/react-collection");
|
||||
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
|
||||
var import_react_context = require("@radix-ui/react-context");
|
||||
var import_react_id = require("@radix-ui/react-id");
|
||||
var import_react_primitive = require("@radix-ui/react-primitive");
|
||||
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
|
||||
var import_react_use_controllable_state = require("@radix-ui/react-use-controllable-state");
|
||||
var import_react_direction = require("@radix-ui/react-direction");
|
||||
var import_jsx_runtime = require("react/jsx-runtime");
|
||||
var ENTRY_FOCUS = "rovingFocusGroup.onEntryFocus";
|
||||
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
||||
var GROUP_NAME = "RovingFocusGroup";
|
||||
var [Collection, useCollection, createCollectionScope] = (0, import_react_collection.createCollection)(GROUP_NAME);
|
||||
var [createRovingFocusGroupContext, createRovingFocusGroupScope] = (0, import_react_context.createContextScope)(
|
||||
GROUP_NAME,
|
||||
[createCollectionScope]
|
||||
);
|
||||
var [RovingFocusProvider, useRovingFocusContext] = createRovingFocusGroupContext(GROUP_NAME);
|
||||
var RovingFocusGroup = React.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Provider, { scope: props.__scopeRovingFocusGroup, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Slot, { scope: props.__scopeRovingFocusGroup, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RovingFocusGroupImpl, { ...props, ref: forwardedRef }) }) });
|
||||
}
|
||||
);
|
||||
RovingFocusGroup.displayName = GROUP_NAME;
|
||||
var RovingFocusGroupImpl = React.forwardRef((props, forwardedRef) => {
|
||||
const {
|
||||
__scopeRovingFocusGroup,
|
||||
orientation,
|
||||
loop = false,
|
||||
dir,
|
||||
currentTabStopId: currentTabStopIdProp,
|
||||
defaultCurrentTabStopId,
|
||||
onCurrentTabStopIdChange,
|
||||
onEntryFocus,
|
||||
preventScrollOnEntryFocus = false,
|
||||
...groupProps
|
||||
} = props;
|
||||
const ref = React.useRef(null);
|
||||
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
|
||||
const direction = (0, import_react_direction.useDirection)(dir);
|
||||
const [currentTabStopId = null, setCurrentTabStopId] = (0, import_react_use_controllable_state.useControllableState)({
|
||||
prop: currentTabStopIdProp,
|
||||
defaultProp: defaultCurrentTabStopId,
|
||||
onChange: onCurrentTabStopIdChange
|
||||
});
|
||||
const [isTabbingBackOut, setIsTabbingBackOut] = React.useState(false);
|
||||
const handleEntryFocus = (0, import_react_use_callback_ref.useCallbackRef)(onEntryFocus);
|
||||
const getItems = useCollection(__scopeRovingFocusGroup);
|
||||
const isClickFocusRef = React.useRef(false);
|
||||
const [focusableItemsCount, setFocusableItemsCount] = React.useState(0);
|
||||
React.useEffect(() => {
|
||||
const node = ref.current;
|
||||
if (node) {
|
||||
node.addEventListener(ENTRY_FOCUS, handleEntryFocus);
|
||||
return () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
|
||||
}
|
||||
}, [handleEntryFocus]);
|
||||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
RovingFocusProvider,
|
||||
{
|
||||
scope: __scopeRovingFocusGroup,
|
||||
orientation,
|
||||
dir: direction,
|
||||
loop,
|
||||
currentTabStopId,
|
||||
onItemFocus: React.useCallback(
|
||||
(tabStopId) => setCurrentTabStopId(tabStopId),
|
||||
[setCurrentTabStopId]
|
||||
),
|
||||
onItemShiftTab: React.useCallback(() => setIsTabbingBackOut(true), []),
|
||||
onFocusableItemAdd: React.useCallback(
|
||||
() => setFocusableItemsCount((prevCount) => prevCount + 1),
|
||||
[]
|
||||
),
|
||||
onFocusableItemRemove: React.useCallback(
|
||||
() => setFocusableItemsCount((prevCount) => prevCount - 1),
|
||||
[]
|
||||
),
|
||||
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
import_react_primitive.Primitive.div,
|
||||
{
|
||||
tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
|
||||
"data-orientation": orientation,
|
||||
...groupProps,
|
||||
ref: composedRefs,
|
||||
style: { outline: "none", ...props.style },
|
||||
onMouseDown: (0, import_primitive.composeEventHandlers)(props.onMouseDown, () => {
|
||||
isClickFocusRef.current = true;
|
||||
}),
|
||||
onFocus: (0, import_primitive.composeEventHandlers)(props.onFocus, (event) => {
|
||||
const isKeyboardFocus = !isClickFocusRef.current;
|
||||
if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
|
||||
const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
|
||||
event.currentTarget.dispatchEvent(entryFocusEvent);
|
||||
if (!entryFocusEvent.defaultPrevented) {
|
||||
const items = getItems().filter((item) => item.focusable);
|
||||
const activeItem = items.find((item) => item.active);
|
||||
const currentItem = items.find((item) => item.id === currentTabStopId);
|
||||
const candidateItems = [activeItem, currentItem, ...items].filter(
|
||||
Boolean
|
||||
);
|
||||
const candidateNodes = candidateItems.map((item) => item.ref.current);
|
||||
focusFirst(candidateNodes, preventScrollOnEntryFocus);
|
||||
}
|
||||
}
|
||||
isClickFocusRef.current = false;
|
||||
}),
|
||||
onBlur: (0, import_primitive.composeEventHandlers)(props.onBlur, () => setIsTabbingBackOut(false))
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
var ITEM_NAME = "RovingFocusGroupItem";
|
||||
var RovingFocusGroupItem = React.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
const {
|
||||
__scopeRovingFocusGroup,
|
||||
focusable = true,
|
||||
active = false,
|
||||
tabStopId,
|
||||
...itemProps
|
||||
} = props;
|
||||
const autoId = (0, import_react_id.useId)();
|
||||
const id = tabStopId || autoId;
|
||||
const context = useRovingFocusContext(ITEM_NAME, __scopeRovingFocusGroup);
|
||||
const isCurrentTabStop = context.currentTabStopId === id;
|
||||
const getItems = useCollection(__scopeRovingFocusGroup);
|
||||
const { onFocusableItemAdd, onFocusableItemRemove } = context;
|
||||
React.useEffect(() => {
|
||||
if (focusable) {
|
||||
onFocusableItemAdd();
|
||||
return () => onFocusableItemRemove();
|
||||
}
|
||||
}, [focusable, onFocusableItemAdd, onFocusableItemRemove]);
|
||||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
Collection.ItemSlot,
|
||||
{
|
||||
scope: __scopeRovingFocusGroup,
|
||||
id,
|
||||
focusable,
|
||||
active,
|
||||
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
||||
import_react_primitive.Primitive.span,
|
||||
{
|
||||
tabIndex: isCurrentTabStop ? 0 : -1,
|
||||
"data-orientation": context.orientation,
|
||||
...itemProps,
|
||||
ref: forwardedRef,
|
||||
onMouseDown: (0, import_primitive.composeEventHandlers)(props.onMouseDown, (event) => {
|
||||
if (!focusable) event.preventDefault();
|
||||
else context.onItemFocus(id);
|
||||
}),
|
||||
onFocus: (0, import_primitive.composeEventHandlers)(props.onFocus, () => context.onItemFocus(id)),
|
||||
onKeyDown: (0, import_primitive.composeEventHandlers)(props.onKeyDown, (event) => {
|
||||
if (event.key === "Tab" && event.shiftKey) {
|
||||
context.onItemShiftTab();
|
||||
return;
|
||||
}
|
||||
if (event.target !== event.currentTarget) return;
|
||||
const focusIntent = getFocusIntent(event, context.orientation, context.dir);
|
||||
if (focusIntent !== void 0) {
|
||||
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
|
||||
event.preventDefault();
|
||||
const items = getItems().filter((item) => item.focusable);
|
||||
let candidateNodes = items.map((item) => item.ref.current);
|
||||
if (focusIntent === "last") candidateNodes.reverse();
|
||||
else if (focusIntent === "prev" || focusIntent === "next") {
|
||||
if (focusIntent === "prev") candidateNodes.reverse();
|
||||
const currentIndex = candidateNodes.indexOf(event.currentTarget);
|
||||
candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
|
||||
}
|
||||
setTimeout(() => focusFirst(candidateNodes));
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
RovingFocusGroupItem.displayName = ITEM_NAME;
|
||||
var MAP_KEY_TO_FOCUS_INTENT = {
|
||||
ArrowLeft: "prev",
|
||||
ArrowUp: "prev",
|
||||
ArrowRight: "next",
|
||||
ArrowDown: "next",
|
||||
PageUp: "first",
|
||||
Home: "first",
|
||||
PageDown: "last",
|
||||
End: "last"
|
||||
};
|
||||
function getDirectionAwareKey(key, dir) {
|
||||
if (dir !== "rtl") return key;
|
||||
return key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
|
||||
}
|
||||
function getFocusIntent(event, orientation, dir) {
|
||||
const key = getDirectionAwareKey(event.key, dir);
|
||||
if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) return void 0;
|
||||
if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)) return void 0;
|
||||
return MAP_KEY_TO_FOCUS_INTENT[key];
|
||||
}
|
||||
function focusFirst(candidates, preventScroll = false) {
|
||||
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
||||
for (const candidate of candidates) {
|
||||
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
|
||||
candidate.focus({ preventScroll });
|
||||
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
|
||||
}
|
||||
}
|
||||
function wrapArray(array, startIndex) {
|
||||
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
||||
}
|
||||
var Root = RovingFocusGroup;
|
||||
var Item = RovingFocusGroupItem;
|
||||
//# sourceMappingURL=index.js.map
|
||||
7
node_modules/@radix-ui/react-roving-focus/dist/index.js.map
generated
vendored
Normal file
7
node_modules/@radix-ui/react-roving-focus/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
228
node_modules/@radix-ui/react-roving-focus/dist/index.mjs
generated
vendored
Normal file
228
node_modules/@radix-ui/react-roving-focus/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
"use client";
|
||||
|
||||
// packages/react/roving-focus/src/roving-focus-group.tsx
|
||||
import * as React from "react";
|
||||
import { composeEventHandlers } from "@radix-ui/primitive";
|
||||
import { createCollection } from "@radix-ui/react-collection";
|
||||
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
||||
import { createContextScope } from "@radix-ui/react-context";
|
||||
import { useId } from "@radix-ui/react-id";
|
||||
import { Primitive } from "@radix-ui/react-primitive";
|
||||
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
||||
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
||||
import { useDirection } from "@radix-ui/react-direction";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
var ENTRY_FOCUS = "rovingFocusGroup.onEntryFocus";
|
||||
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
||||
var GROUP_NAME = "RovingFocusGroup";
|
||||
var [Collection, useCollection, createCollectionScope] = createCollection(GROUP_NAME);
|
||||
var [createRovingFocusGroupContext, createRovingFocusGroupScope] = createContextScope(
|
||||
GROUP_NAME,
|
||||
[createCollectionScope]
|
||||
);
|
||||
var [RovingFocusProvider, useRovingFocusContext] = createRovingFocusGroupContext(GROUP_NAME);
|
||||
var RovingFocusGroup = React.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
return /* @__PURE__ */ jsx(Collection.Provider, { scope: props.__scopeRovingFocusGroup, children: /* @__PURE__ */ jsx(Collection.Slot, { scope: props.__scopeRovingFocusGroup, children: /* @__PURE__ */ jsx(RovingFocusGroupImpl, { ...props, ref: forwardedRef }) }) });
|
||||
}
|
||||
);
|
||||
RovingFocusGroup.displayName = GROUP_NAME;
|
||||
var RovingFocusGroupImpl = React.forwardRef((props, forwardedRef) => {
|
||||
const {
|
||||
__scopeRovingFocusGroup,
|
||||
orientation,
|
||||
loop = false,
|
||||
dir,
|
||||
currentTabStopId: currentTabStopIdProp,
|
||||
defaultCurrentTabStopId,
|
||||
onCurrentTabStopIdChange,
|
||||
onEntryFocus,
|
||||
preventScrollOnEntryFocus = false,
|
||||
...groupProps
|
||||
} = props;
|
||||
const ref = React.useRef(null);
|
||||
const composedRefs = useComposedRefs(forwardedRef, ref);
|
||||
const direction = useDirection(dir);
|
||||
const [currentTabStopId = null, setCurrentTabStopId] = useControllableState({
|
||||
prop: currentTabStopIdProp,
|
||||
defaultProp: defaultCurrentTabStopId,
|
||||
onChange: onCurrentTabStopIdChange
|
||||
});
|
||||
const [isTabbingBackOut, setIsTabbingBackOut] = React.useState(false);
|
||||
const handleEntryFocus = useCallbackRef(onEntryFocus);
|
||||
const getItems = useCollection(__scopeRovingFocusGroup);
|
||||
const isClickFocusRef = React.useRef(false);
|
||||
const [focusableItemsCount, setFocusableItemsCount] = React.useState(0);
|
||||
React.useEffect(() => {
|
||||
const node = ref.current;
|
||||
if (node) {
|
||||
node.addEventListener(ENTRY_FOCUS, handleEntryFocus);
|
||||
return () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
|
||||
}
|
||||
}, [handleEntryFocus]);
|
||||
return /* @__PURE__ */ jsx(
|
||||
RovingFocusProvider,
|
||||
{
|
||||
scope: __scopeRovingFocusGroup,
|
||||
orientation,
|
||||
dir: direction,
|
||||
loop,
|
||||
currentTabStopId,
|
||||
onItemFocus: React.useCallback(
|
||||
(tabStopId) => setCurrentTabStopId(tabStopId),
|
||||
[setCurrentTabStopId]
|
||||
),
|
||||
onItemShiftTab: React.useCallback(() => setIsTabbingBackOut(true), []),
|
||||
onFocusableItemAdd: React.useCallback(
|
||||
() => setFocusableItemsCount((prevCount) => prevCount + 1),
|
||||
[]
|
||||
),
|
||||
onFocusableItemRemove: React.useCallback(
|
||||
() => setFocusableItemsCount((prevCount) => prevCount - 1),
|
||||
[]
|
||||
),
|
||||
children: /* @__PURE__ */ jsx(
|
||||
Primitive.div,
|
||||
{
|
||||
tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
|
||||
"data-orientation": orientation,
|
||||
...groupProps,
|
||||
ref: composedRefs,
|
||||
style: { outline: "none", ...props.style },
|
||||
onMouseDown: composeEventHandlers(props.onMouseDown, () => {
|
||||
isClickFocusRef.current = true;
|
||||
}),
|
||||
onFocus: composeEventHandlers(props.onFocus, (event) => {
|
||||
const isKeyboardFocus = !isClickFocusRef.current;
|
||||
if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
|
||||
const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
|
||||
event.currentTarget.dispatchEvent(entryFocusEvent);
|
||||
if (!entryFocusEvent.defaultPrevented) {
|
||||
const items = getItems().filter((item) => item.focusable);
|
||||
const activeItem = items.find((item) => item.active);
|
||||
const currentItem = items.find((item) => item.id === currentTabStopId);
|
||||
const candidateItems = [activeItem, currentItem, ...items].filter(
|
||||
Boolean
|
||||
);
|
||||
const candidateNodes = candidateItems.map((item) => item.ref.current);
|
||||
focusFirst(candidateNodes, preventScrollOnEntryFocus);
|
||||
}
|
||||
}
|
||||
isClickFocusRef.current = false;
|
||||
}),
|
||||
onBlur: composeEventHandlers(props.onBlur, () => setIsTabbingBackOut(false))
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
var ITEM_NAME = "RovingFocusGroupItem";
|
||||
var RovingFocusGroupItem = React.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
const {
|
||||
__scopeRovingFocusGroup,
|
||||
focusable = true,
|
||||
active = false,
|
||||
tabStopId,
|
||||
...itemProps
|
||||
} = props;
|
||||
const autoId = useId();
|
||||
const id = tabStopId || autoId;
|
||||
const context = useRovingFocusContext(ITEM_NAME, __scopeRovingFocusGroup);
|
||||
const isCurrentTabStop = context.currentTabStopId === id;
|
||||
const getItems = useCollection(__scopeRovingFocusGroup);
|
||||
const { onFocusableItemAdd, onFocusableItemRemove } = context;
|
||||
React.useEffect(() => {
|
||||
if (focusable) {
|
||||
onFocusableItemAdd();
|
||||
return () => onFocusableItemRemove();
|
||||
}
|
||||
}, [focusable, onFocusableItemAdd, onFocusableItemRemove]);
|
||||
return /* @__PURE__ */ jsx(
|
||||
Collection.ItemSlot,
|
||||
{
|
||||
scope: __scopeRovingFocusGroup,
|
||||
id,
|
||||
focusable,
|
||||
active,
|
||||
children: /* @__PURE__ */ jsx(
|
||||
Primitive.span,
|
||||
{
|
||||
tabIndex: isCurrentTabStop ? 0 : -1,
|
||||
"data-orientation": context.orientation,
|
||||
...itemProps,
|
||||
ref: forwardedRef,
|
||||
onMouseDown: composeEventHandlers(props.onMouseDown, (event) => {
|
||||
if (!focusable) event.preventDefault();
|
||||
else context.onItemFocus(id);
|
||||
}),
|
||||
onFocus: composeEventHandlers(props.onFocus, () => context.onItemFocus(id)),
|
||||
onKeyDown: composeEventHandlers(props.onKeyDown, (event) => {
|
||||
if (event.key === "Tab" && event.shiftKey) {
|
||||
context.onItemShiftTab();
|
||||
return;
|
||||
}
|
||||
if (event.target !== event.currentTarget) return;
|
||||
const focusIntent = getFocusIntent(event, context.orientation, context.dir);
|
||||
if (focusIntent !== void 0) {
|
||||
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
|
||||
event.preventDefault();
|
||||
const items = getItems().filter((item) => item.focusable);
|
||||
let candidateNodes = items.map((item) => item.ref.current);
|
||||
if (focusIntent === "last") candidateNodes.reverse();
|
||||
else if (focusIntent === "prev" || focusIntent === "next") {
|
||||
if (focusIntent === "prev") candidateNodes.reverse();
|
||||
const currentIndex = candidateNodes.indexOf(event.currentTarget);
|
||||
candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
|
||||
}
|
||||
setTimeout(() => focusFirst(candidateNodes));
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
RovingFocusGroupItem.displayName = ITEM_NAME;
|
||||
var MAP_KEY_TO_FOCUS_INTENT = {
|
||||
ArrowLeft: "prev",
|
||||
ArrowUp: "prev",
|
||||
ArrowRight: "next",
|
||||
ArrowDown: "next",
|
||||
PageUp: "first",
|
||||
Home: "first",
|
||||
PageDown: "last",
|
||||
End: "last"
|
||||
};
|
||||
function getDirectionAwareKey(key, dir) {
|
||||
if (dir !== "rtl") return key;
|
||||
return key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
|
||||
}
|
||||
function getFocusIntent(event, orientation, dir) {
|
||||
const key = getDirectionAwareKey(event.key, dir);
|
||||
if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) return void 0;
|
||||
if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)) return void 0;
|
||||
return MAP_KEY_TO_FOCUS_INTENT[key];
|
||||
}
|
||||
function focusFirst(candidates, preventScroll = false) {
|
||||
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
||||
for (const candidate of candidates) {
|
||||
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
|
||||
candidate.focus({ preventScroll });
|
||||
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
|
||||
}
|
||||
}
|
||||
function wrapArray(array, startIndex) {
|
||||
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
||||
}
|
||||
var Root = RovingFocusGroup;
|
||||
var Item = RovingFocusGroupItem;
|
||||
export {
|
||||
Item,
|
||||
Root,
|
||||
RovingFocusGroup,
|
||||
RovingFocusGroupItem,
|
||||
createRovingFocusGroupScope
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
7
node_modules/@radix-ui/react-roving-focus/dist/index.mjs.map
generated
vendored
Normal file
7
node_modules/@radix-ui/react-roving-focus/dist/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
101
node_modules/@radix-ui/react-roving-focus/package.json
generated
vendored
Normal file
101
node_modules/@radix-ui/react-roving-focus/package.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"_from": "@radix-ui/react-roving-focus@1.1.2",
|
||||
"_id": "@radix-ui/react-roving-focus@1.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-zgMQWkNO169GtGqRvYrzb0Zf8NhMHS2DuEB/TiEmVnpr5OqPU3i8lfbxaAmC2J/KYuIQxyoQQ6DxepyXp61/xw==",
|
||||
"_location": "/@radix-ui/react-roving-focus",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@radix-ui/react-roving-focus@1.1.2",
|
||||
"name": "@radix-ui/react-roving-focus",
|
||||
"escapedName": "@radix-ui%2freact-roving-focus",
|
||||
"scope": "@radix-ui",
|
||||
"rawSpec": "1.1.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.1.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@radix-ui/react-menu"
|
||||
],
|
||||
"_resolved": "https://registry.npmmirror.com/@radix-ui/react-roving-focus/-/react-roving-focus-1.1.2.tgz",
|
||||
"_shasum": "815d051a54299114a68db6eb8d34c41a3c0a646f",
|
||||
"_spec": "@radix-ui/react-roving-focus@1.1.2",
|
||||
"_where": "/Users/hongbin9/www/botgroup.chat/node_modules/@radix-ui/react-menu",
|
||||
"bugs": {
|
||||
"url": "https://github.com/radix-ui/primitives/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@radix-ui/primitive": "1.1.1",
|
||||
"@radix-ui/react-collection": "1.1.2",
|
||||
"@radix-ui/react-compose-refs": "1.1.1",
|
||||
"@radix-ui/react-context": "1.1.1",
|
||||
"@radix-ui/react-direction": "1.1.0",
|
||||
"@radix-ui/react-id": "1.1.0",
|
||||
"@radix-ui/react-primitive": "2.0.2",
|
||||
"@radix-ui/react-use-callback-ref": "1.1.0",
|
||||
"@radix-ui/react-use-controllable-state": "1.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "## Installation",
|
||||
"devDependencies": {
|
||||
"@repo/eslint-config": "0.0.0",
|
||||
"@repo/typescript-config": "0.0.0",
|
||||
"@types/react": "^19.0.7",
|
||||
"@types/react-dom": "^19.0.3",
|
||||
"eslint": "^9.18.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"typescript": "^5.7.3"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": {
|
||||
"types": "./dist/index.d.mts",
|
||||
"default": "./dist/index.mjs"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"README.md"
|
||||
],
|
||||
"homepage": "https://radix-ui.com/primitives",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"name": "@radix-ui/react-roving-focus",
|
||||
"peerDependencies": {
|
||||
"@types/react": "*",
|
||||
"@types/react-dom": "*",
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/react-dom": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/radix-ui/primitives.git"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf dist",
|
||||
"lint": "eslint --max-warnings 0 src",
|
||||
"version": "yarn version"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"version": "1.1.2"
|
||||
}
|
||||
Reference in New Issue
Block a user