Initial commit
This commit is contained in:
13
node_modules/@radix-ui/react-focus-scope/README.md
generated
vendored
Normal file
13
node_modules/@radix-ui/react-focus-scope/README.md
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# `react-focus-scope`
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ yarn add @radix-ui/react-focus-scope
|
||||
# or
|
||||
$ npm install @radix-ui/react-focus-scope
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This is an internal utility, not intended for public usage.
|
||||
32
node_modules/@radix-ui/react-focus-scope/dist/index.d.mts
generated
vendored
Normal file
32
node_modules/@radix-ui/react-focus-scope/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as React from 'react';
|
||||
import { Primitive } from '@radix-ui/react-primitive';
|
||||
|
||||
type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
|
||||
interface FocusScopeProps extends PrimitiveDivProps {
|
||||
/**
|
||||
* When `true`, tabbing from last item will focus first tabbable
|
||||
* and shift+tab from first item will focus last tababble.
|
||||
* @defaultValue false
|
||||
*/
|
||||
loop?: boolean;
|
||||
/**
|
||||
* When `true`, focus cannot escape the focus scope via keyboard,
|
||||
* pointer, or a programmatic focus.
|
||||
* @defaultValue false
|
||||
*/
|
||||
trapped?: boolean;
|
||||
/**
|
||||
* Event handler called when auto-focusing on mount.
|
||||
* Can be prevented.
|
||||
*/
|
||||
onMountAutoFocus?: (event: Event) => void;
|
||||
/**
|
||||
* Event handler called when auto-focusing on unmount.
|
||||
* Can be prevented.
|
||||
*/
|
||||
onUnmountAutoFocus?: (event: Event) => void;
|
||||
}
|
||||
declare const FocusScope: React.ForwardRefExoticComponent<FocusScopeProps & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const Root: React.ForwardRefExoticComponent<FocusScopeProps & React.RefAttributes<HTMLDivElement>>;
|
||||
|
||||
export { FocusScope, type FocusScopeProps, Root };
|
||||
32
node_modules/@radix-ui/react-focus-scope/dist/index.d.ts
generated
vendored
Normal file
32
node_modules/@radix-ui/react-focus-scope/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import * as React from 'react';
|
||||
import { Primitive } from '@radix-ui/react-primitive';
|
||||
|
||||
type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
|
||||
interface FocusScopeProps extends PrimitiveDivProps {
|
||||
/**
|
||||
* When `true`, tabbing from last item will focus first tabbable
|
||||
* and shift+tab from first item will focus last tababble.
|
||||
* @defaultValue false
|
||||
*/
|
||||
loop?: boolean;
|
||||
/**
|
||||
* When `true`, focus cannot escape the focus scope via keyboard,
|
||||
* pointer, or a programmatic focus.
|
||||
* @defaultValue false
|
||||
*/
|
||||
trapped?: boolean;
|
||||
/**
|
||||
* Event handler called when auto-focusing on mount.
|
||||
* Can be prevented.
|
||||
*/
|
||||
onMountAutoFocus?: (event: Event) => void;
|
||||
/**
|
||||
* Event handler called when auto-focusing on unmount.
|
||||
* Can be prevented.
|
||||
*/
|
||||
onUnmountAutoFocus?: (event: Event) => void;
|
||||
}
|
||||
declare const FocusScope: React.ForwardRefExoticComponent<FocusScopeProps & React.RefAttributes<HTMLDivElement>>;
|
||||
declare const Root: React.ForwardRefExoticComponent<FocusScopeProps & React.RefAttributes<HTMLDivElement>>;
|
||||
|
||||
export { FocusScope, type FocusScopeProps, Root };
|
||||
246
node_modules/@radix-ui/react-focus-scope/dist/index.js
generated
vendored
Normal file
246
node_modules/@radix-ui/react-focus-scope/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
"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/focus-scope/src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
FocusScope: () => FocusScope,
|
||||
Root: () => Root
|
||||
});
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
|
||||
// packages/react/focus-scope/src/focus-scope.tsx
|
||||
var React = __toESM(require("react"));
|
||||
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
|
||||
var import_react_primitive = require("@radix-ui/react-primitive");
|
||||
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
|
||||
var import_jsx_runtime = require("react/jsx-runtime");
|
||||
var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
||||
var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
||||
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
||||
var FOCUS_SCOPE_NAME = "FocusScope";
|
||||
var FocusScope = React.forwardRef((props, forwardedRef) => {
|
||||
const {
|
||||
loop = false,
|
||||
trapped = false,
|
||||
onMountAutoFocus: onMountAutoFocusProp,
|
||||
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
||||
...scopeProps
|
||||
} = props;
|
||||
const [container, setContainer] = React.useState(null);
|
||||
const onMountAutoFocus = (0, import_react_use_callback_ref.useCallbackRef)(onMountAutoFocusProp);
|
||||
const onUnmountAutoFocus = (0, import_react_use_callback_ref.useCallbackRef)(onUnmountAutoFocusProp);
|
||||
const lastFocusedElementRef = React.useRef(null);
|
||||
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node) => setContainer(node));
|
||||
const focusScope = React.useRef({
|
||||
paused: false,
|
||||
pause() {
|
||||
this.paused = true;
|
||||
},
|
||||
resume() {
|
||||
this.paused = false;
|
||||
}
|
||||
}).current;
|
||||
React.useEffect(() => {
|
||||
if (trapped) {
|
||||
let handleFocusIn2 = function(event) {
|
||||
if (focusScope.paused || !container) return;
|
||||
const target = event.target;
|
||||
if (container.contains(target)) {
|
||||
lastFocusedElementRef.current = target;
|
||||
} else {
|
||||
focus(lastFocusedElementRef.current, { select: true });
|
||||
}
|
||||
}, handleFocusOut2 = function(event) {
|
||||
if (focusScope.paused || !container) return;
|
||||
const relatedTarget = event.relatedTarget;
|
||||
if (relatedTarget === null) return;
|
||||
if (!container.contains(relatedTarget)) {
|
||||
focus(lastFocusedElementRef.current, { select: true });
|
||||
}
|
||||
}, handleMutations2 = function(mutations) {
|
||||
const focusedElement = document.activeElement;
|
||||
if (focusedElement !== document.body) return;
|
||||
for (const mutation of mutations) {
|
||||
if (mutation.removedNodes.length > 0) focus(container);
|
||||
}
|
||||
};
|
||||
var handleFocusIn = handleFocusIn2, handleFocusOut = handleFocusOut2, handleMutations = handleMutations2;
|
||||
document.addEventListener("focusin", handleFocusIn2);
|
||||
document.addEventListener("focusout", handleFocusOut2);
|
||||
const mutationObserver = new MutationObserver(handleMutations2);
|
||||
if (container) mutationObserver.observe(container, { childList: true, subtree: true });
|
||||
return () => {
|
||||
document.removeEventListener("focusin", handleFocusIn2);
|
||||
document.removeEventListener("focusout", handleFocusOut2);
|
||||
mutationObserver.disconnect();
|
||||
};
|
||||
}
|
||||
}, [trapped, container, focusScope.paused]);
|
||||
React.useEffect(() => {
|
||||
if (container) {
|
||||
focusScopesStack.add(focusScope);
|
||||
const previouslyFocusedElement = document.activeElement;
|
||||
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
||||
if (!hasFocusedCandidate) {
|
||||
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
||||
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
||||
container.dispatchEvent(mountEvent);
|
||||
if (!mountEvent.defaultPrevented) {
|
||||
focusFirst(removeLinks(getTabbableCandidates(container)), { select: true });
|
||||
if (document.activeElement === previouslyFocusedElement) {
|
||||
focus(container);
|
||||
}
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
||||
setTimeout(() => {
|
||||
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
||||
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
||||
container.dispatchEvent(unmountEvent);
|
||||
if (!unmountEvent.defaultPrevented) {
|
||||
focus(previouslyFocusedElement ?? document.body, { select: true });
|
||||
}
|
||||
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
||||
focusScopesStack.remove(focusScope);
|
||||
}, 0);
|
||||
};
|
||||
}
|
||||
}, [container, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
||||
const handleKeyDown = React.useCallback(
|
||||
(event) => {
|
||||
if (!loop && !trapped) return;
|
||||
if (focusScope.paused) return;
|
||||
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
||||
const focusedElement = document.activeElement;
|
||||
if (isTabKey && focusedElement) {
|
||||
const container2 = event.currentTarget;
|
||||
const [first, last] = getTabbableEdges(container2);
|
||||
const hasTabbableElementsInside = first && last;
|
||||
if (!hasTabbableElementsInside) {
|
||||
if (focusedElement === container2) event.preventDefault();
|
||||
} else {
|
||||
if (!event.shiftKey && focusedElement === last) {
|
||||
event.preventDefault();
|
||||
if (loop) focus(first, { select: true });
|
||||
} else if (event.shiftKey && focusedElement === first) {
|
||||
event.preventDefault();
|
||||
if (loop) focus(last, { select: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
[loop, trapped, focusScope.paused]
|
||||
);
|
||||
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { tabIndex: -1, ...scopeProps, ref: composedRefs, onKeyDown: handleKeyDown });
|
||||
});
|
||||
FocusScope.displayName = FOCUS_SCOPE_NAME;
|
||||
function focusFirst(candidates, { select = false } = {}) {
|
||||
const previouslyFocusedElement = document.activeElement;
|
||||
for (const candidate of candidates) {
|
||||
focus(candidate, { select });
|
||||
if (document.activeElement !== previouslyFocusedElement) return;
|
||||
}
|
||||
}
|
||||
function getTabbableEdges(container) {
|
||||
const candidates = getTabbableCandidates(container);
|
||||
const first = findVisible(candidates, container);
|
||||
const last = findVisible(candidates.reverse(), container);
|
||||
return [first, last];
|
||||
}
|
||||
function getTabbableCandidates(container) {
|
||||
const nodes = [];
|
||||
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
||||
acceptNode: (node) => {
|
||||
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
||||
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
||||
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
||||
}
|
||||
});
|
||||
while (walker.nextNode()) nodes.push(walker.currentNode);
|
||||
return nodes;
|
||||
}
|
||||
function findVisible(elements, container) {
|
||||
for (const element of elements) {
|
||||
if (!isHidden(element, { upTo: container })) return element;
|
||||
}
|
||||
}
|
||||
function isHidden(node, { upTo }) {
|
||||
if (getComputedStyle(node).visibility === "hidden") return true;
|
||||
while (node) {
|
||||
if (upTo !== void 0 && node === upTo) return false;
|
||||
if (getComputedStyle(node).display === "none") return true;
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isSelectableInput(element) {
|
||||
return element instanceof HTMLInputElement && "select" in element;
|
||||
}
|
||||
function focus(element, { select = false } = {}) {
|
||||
if (element && element.focus) {
|
||||
const previouslyFocusedElement = document.activeElement;
|
||||
element.focus({ preventScroll: true });
|
||||
if (element !== previouslyFocusedElement && isSelectableInput(element) && select)
|
||||
element.select();
|
||||
}
|
||||
}
|
||||
var focusScopesStack = createFocusScopesStack();
|
||||
function createFocusScopesStack() {
|
||||
let stack = [];
|
||||
return {
|
||||
add(focusScope) {
|
||||
const activeFocusScope = stack[0];
|
||||
if (focusScope !== activeFocusScope) {
|
||||
activeFocusScope?.pause();
|
||||
}
|
||||
stack = arrayRemove(stack, focusScope);
|
||||
stack.unshift(focusScope);
|
||||
},
|
||||
remove(focusScope) {
|
||||
stack = arrayRemove(stack, focusScope);
|
||||
stack[0]?.resume();
|
||||
}
|
||||
};
|
||||
}
|
||||
function arrayRemove(array, item) {
|
||||
const updatedArray = [...array];
|
||||
const index = updatedArray.indexOf(item);
|
||||
if (index !== -1) {
|
||||
updatedArray.splice(index, 1);
|
||||
}
|
||||
return updatedArray;
|
||||
}
|
||||
function removeLinks(items) {
|
||||
return items.filter((item) => item.tagName !== "A");
|
||||
}
|
||||
var Root = FocusScope;
|
||||
//# sourceMappingURL=index.js.map
|
||||
7
node_modules/@radix-ui/react-focus-scope/dist/index.js.map
generated
vendored
Normal file
7
node_modules/@radix-ui/react-focus-scope/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
214
node_modules/@radix-ui/react-focus-scope/dist/index.mjs
generated
vendored
Normal file
214
node_modules/@radix-ui/react-focus-scope/dist/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,214 @@
|
||||
"use client";
|
||||
|
||||
// packages/react/focus-scope/src/focus-scope.tsx
|
||||
import * as React from "react";
|
||||
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
||||
import { Primitive } from "@radix-ui/react-primitive";
|
||||
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
var AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount";
|
||||
var AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount";
|
||||
var EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
||||
var FOCUS_SCOPE_NAME = "FocusScope";
|
||||
var FocusScope = React.forwardRef((props, forwardedRef) => {
|
||||
const {
|
||||
loop = false,
|
||||
trapped = false,
|
||||
onMountAutoFocus: onMountAutoFocusProp,
|
||||
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
||||
...scopeProps
|
||||
} = props;
|
||||
const [container, setContainer] = React.useState(null);
|
||||
const onMountAutoFocus = useCallbackRef(onMountAutoFocusProp);
|
||||
const onUnmountAutoFocus = useCallbackRef(onUnmountAutoFocusProp);
|
||||
const lastFocusedElementRef = React.useRef(null);
|
||||
const composedRefs = useComposedRefs(forwardedRef, (node) => setContainer(node));
|
||||
const focusScope = React.useRef({
|
||||
paused: false,
|
||||
pause() {
|
||||
this.paused = true;
|
||||
},
|
||||
resume() {
|
||||
this.paused = false;
|
||||
}
|
||||
}).current;
|
||||
React.useEffect(() => {
|
||||
if (trapped) {
|
||||
let handleFocusIn2 = function(event) {
|
||||
if (focusScope.paused || !container) return;
|
||||
const target = event.target;
|
||||
if (container.contains(target)) {
|
||||
lastFocusedElementRef.current = target;
|
||||
} else {
|
||||
focus(lastFocusedElementRef.current, { select: true });
|
||||
}
|
||||
}, handleFocusOut2 = function(event) {
|
||||
if (focusScope.paused || !container) return;
|
||||
const relatedTarget = event.relatedTarget;
|
||||
if (relatedTarget === null) return;
|
||||
if (!container.contains(relatedTarget)) {
|
||||
focus(lastFocusedElementRef.current, { select: true });
|
||||
}
|
||||
}, handleMutations2 = function(mutations) {
|
||||
const focusedElement = document.activeElement;
|
||||
if (focusedElement !== document.body) return;
|
||||
for (const mutation of mutations) {
|
||||
if (mutation.removedNodes.length > 0) focus(container);
|
||||
}
|
||||
};
|
||||
var handleFocusIn = handleFocusIn2, handleFocusOut = handleFocusOut2, handleMutations = handleMutations2;
|
||||
document.addEventListener("focusin", handleFocusIn2);
|
||||
document.addEventListener("focusout", handleFocusOut2);
|
||||
const mutationObserver = new MutationObserver(handleMutations2);
|
||||
if (container) mutationObserver.observe(container, { childList: true, subtree: true });
|
||||
return () => {
|
||||
document.removeEventListener("focusin", handleFocusIn2);
|
||||
document.removeEventListener("focusout", handleFocusOut2);
|
||||
mutationObserver.disconnect();
|
||||
};
|
||||
}
|
||||
}, [trapped, container, focusScope.paused]);
|
||||
React.useEffect(() => {
|
||||
if (container) {
|
||||
focusScopesStack.add(focusScope);
|
||||
const previouslyFocusedElement = document.activeElement;
|
||||
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
||||
if (!hasFocusedCandidate) {
|
||||
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
||||
container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
||||
container.dispatchEvent(mountEvent);
|
||||
if (!mountEvent.defaultPrevented) {
|
||||
focusFirst(removeLinks(getTabbableCandidates(container)), { select: true });
|
||||
if (document.activeElement === previouslyFocusedElement) {
|
||||
focus(container);
|
||||
}
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
||||
setTimeout(() => {
|
||||
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
||||
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
||||
container.dispatchEvent(unmountEvent);
|
||||
if (!unmountEvent.defaultPrevented) {
|
||||
focus(previouslyFocusedElement ?? document.body, { select: true });
|
||||
}
|
||||
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus);
|
||||
focusScopesStack.remove(focusScope);
|
||||
}, 0);
|
||||
};
|
||||
}
|
||||
}, [container, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
||||
const handleKeyDown = React.useCallback(
|
||||
(event) => {
|
||||
if (!loop && !trapped) return;
|
||||
if (focusScope.paused) return;
|
||||
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey;
|
||||
const focusedElement = document.activeElement;
|
||||
if (isTabKey && focusedElement) {
|
||||
const container2 = event.currentTarget;
|
||||
const [first, last] = getTabbableEdges(container2);
|
||||
const hasTabbableElementsInside = first && last;
|
||||
if (!hasTabbableElementsInside) {
|
||||
if (focusedElement === container2) event.preventDefault();
|
||||
} else {
|
||||
if (!event.shiftKey && focusedElement === last) {
|
||||
event.preventDefault();
|
||||
if (loop) focus(first, { select: true });
|
||||
} else if (event.shiftKey && focusedElement === first) {
|
||||
event.preventDefault();
|
||||
if (loop) focus(last, { select: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
[loop, trapped, focusScope.paused]
|
||||
);
|
||||
return /* @__PURE__ */ jsx(Primitive.div, { tabIndex: -1, ...scopeProps, ref: composedRefs, onKeyDown: handleKeyDown });
|
||||
});
|
||||
FocusScope.displayName = FOCUS_SCOPE_NAME;
|
||||
function focusFirst(candidates, { select = false } = {}) {
|
||||
const previouslyFocusedElement = document.activeElement;
|
||||
for (const candidate of candidates) {
|
||||
focus(candidate, { select });
|
||||
if (document.activeElement !== previouslyFocusedElement) return;
|
||||
}
|
||||
}
|
||||
function getTabbableEdges(container) {
|
||||
const candidates = getTabbableCandidates(container);
|
||||
const first = findVisible(candidates, container);
|
||||
const last = findVisible(candidates.reverse(), container);
|
||||
return [first, last];
|
||||
}
|
||||
function getTabbableCandidates(container) {
|
||||
const nodes = [];
|
||||
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
||||
acceptNode: (node) => {
|
||||
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
||||
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
||||
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
||||
}
|
||||
});
|
||||
while (walker.nextNode()) nodes.push(walker.currentNode);
|
||||
return nodes;
|
||||
}
|
||||
function findVisible(elements, container) {
|
||||
for (const element of elements) {
|
||||
if (!isHidden(element, { upTo: container })) return element;
|
||||
}
|
||||
}
|
||||
function isHidden(node, { upTo }) {
|
||||
if (getComputedStyle(node).visibility === "hidden") return true;
|
||||
while (node) {
|
||||
if (upTo !== void 0 && node === upTo) return false;
|
||||
if (getComputedStyle(node).display === "none") return true;
|
||||
node = node.parentElement;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isSelectableInput(element) {
|
||||
return element instanceof HTMLInputElement && "select" in element;
|
||||
}
|
||||
function focus(element, { select = false } = {}) {
|
||||
if (element && element.focus) {
|
||||
const previouslyFocusedElement = document.activeElement;
|
||||
element.focus({ preventScroll: true });
|
||||
if (element !== previouslyFocusedElement && isSelectableInput(element) && select)
|
||||
element.select();
|
||||
}
|
||||
}
|
||||
var focusScopesStack = createFocusScopesStack();
|
||||
function createFocusScopesStack() {
|
||||
let stack = [];
|
||||
return {
|
||||
add(focusScope) {
|
||||
const activeFocusScope = stack[0];
|
||||
if (focusScope !== activeFocusScope) {
|
||||
activeFocusScope?.pause();
|
||||
}
|
||||
stack = arrayRemove(stack, focusScope);
|
||||
stack.unshift(focusScope);
|
||||
},
|
||||
remove(focusScope) {
|
||||
stack = arrayRemove(stack, focusScope);
|
||||
stack[0]?.resume();
|
||||
}
|
||||
};
|
||||
}
|
||||
function arrayRemove(array, item) {
|
||||
const updatedArray = [...array];
|
||||
const index = updatedArray.indexOf(item);
|
||||
if (index !== -1) {
|
||||
updatedArray.splice(index, 1);
|
||||
}
|
||||
return updatedArray;
|
||||
}
|
||||
function removeLinks(items) {
|
||||
return items.filter((item) => item.tagName !== "A");
|
||||
}
|
||||
var Root = FocusScope;
|
||||
export {
|
||||
FocusScope,
|
||||
Root
|
||||
};
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
7
node_modules/@radix-ui/react-focus-scope/dist/index.mjs.map
generated
vendored
Normal file
7
node_modules/@radix-ui/react-focus-scope/dist/index.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
96
node_modules/@radix-ui/react-focus-scope/package.json
generated
vendored
Normal file
96
node_modules/@radix-ui/react-focus-scope/package.json
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
{
|
||||
"_from": "@radix-ui/react-focus-scope@1.1.2",
|
||||
"_id": "@radix-ui/react-focus-scope@1.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-zxwE80FCU7lcXUGWkdt6XpTTCKPitG1XKOwViTxHVKIJhZl9MvIl2dVHeZENCWD9+EdWv05wlaEkRXUykU27RA==",
|
||||
"_location": "/@radix-ui/react-focus-scope",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@radix-ui/react-focus-scope@1.1.2",
|
||||
"name": "@radix-ui/react-focus-scope",
|
||||
"escapedName": "@radix-ui%2freact-focus-scope",
|
||||
"scope": "@radix-ui",
|
||||
"rawSpec": "1.1.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.1.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@radix-ui/react-dialog",
|
||||
"/@radix-ui/react-menu"
|
||||
],
|
||||
"_resolved": "https://registry.npmmirror.com/@radix-ui/react-focus-scope/-/react-focus-scope-1.1.2.tgz",
|
||||
"_shasum": "c0a4519cd95c772606a82fc5b96226cd7fdd2602",
|
||||
"_spec": "@radix-ui/react-focus-scope@1.1.2",
|
||||
"_where": "/Users/hongbin9/www/botgroup.chat/node_modules/@radix-ui/react-dialog",
|
||||
"bugs": {
|
||||
"url": "https://github.com/radix-ui/primitives/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"@radix-ui/react-compose-refs": "1.1.1",
|
||||
"@radix-ui/react-primitive": "2.0.2",
|
||||
"@radix-ui/react-use-callback-ref": "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-focus-scope",
|
||||
"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