build revisions and layout updates for toast

This commit is contained in:
makearmy 2025-09-26 14:31:18 -04:00
parent b341a3675e
commit 39235193e6
1116 changed files with 130517 additions and 12 deletions

21
node_modules/@radix-ui/react-toast/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
node_modules/@radix-ui/react-toast/README.md generated vendored Normal file
View file

@ -0,0 +1,3 @@
# `react-toast`
View docs [here](https://radix-ui.com/primitives/docs/components/toast).

120
node_modules/@radix-ui/react-toast/dist/index.d.mts generated vendored Normal file
View file

@ -0,0 +1,120 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import * as React from 'react';
import * as DismissableLayer from '@radix-ui/react-dismissable-layer';
import { Primitive } from '@radix-ui/react-primitive';
type SwipeDirection = 'up' | 'down' | 'left' | 'right';
declare const createToastScope: _radix_ui_react_context.CreateScope;
interface ToastProviderProps {
children?: React.ReactNode;
/**
* An author-localized label for each toast. Used to help screen reader users
* associate the interruption with a toast.
* @defaultValue 'Notification'
*/
label?: string;
/**
* Time in milliseconds that each toast should remain visible for.
* @defaultValue 5000
*/
duration?: number;
/**
* Direction of pointer swipe that should close the toast.
* @defaultValue 'right'
*/
swipeDirection?: SwipeDirection;
/**
* Distance in pixels that the swipe must pass before a close is triggered.
* @defaultValue 50
*/
swipeThreshold?: number;
}
declare const ToastProvider: React.FC<ToastProviderProps>;
type PrimitiveOrderedListProps = React.ComponentPropsWithoutRef<typeof Primitive.ol>;
interface ToastViewportProps extends PrimitiveOrderedListProps {
/**
* The keys to use as the keyboard shortcut that will move focus to the toast viewport.
* @defaultValue ['F8']
*/
hotkey?: string[];
/**
* An author-localized label for the toast viewport to provide context for screen reader users
* when navigating page landmarks. The available `{hotkey}` placeholder will be replaced for you.
* @defaultValue 'Notifications ({hotkey})'
*/
label?: string;
}
declare const ToastViewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
type ToastElement = ToastImplElement;
interface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {
open?: boolean;
defaultOpen?: boolean;
onOpenChange?(open: boolean): void;
/**
* Used to force mounting when more control is needed. Useful when
* controlling animation with React animation libraries.
*/
forceMount?: true;
}
declare const Toast: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
type SwipeEvent = {
currentTarget: EventTarget & ToastElement;
} & Omit<CustomEvent<{
originalEvent: React.PointerEvent;
delta: {
x: number;
y: number;
};
}>, 'currentTarget'>;
type ToastImplElement = React.ComponentRef<typeof Primitive.li>;
type DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer.Root>;
type ToastImplPrivateProps = {
open: boolean;
onClose(): void;
};
type PrimitiveListItemProps = React.ComponentPropsWithoutRef<typeof Primitive.li>;
interface ToastImplProps extends ToastImplPrivateProps, PrimitiveListItemProps {
type?: 'foreground' | 'background';
/**
* Time in milliseconds that toast should remain visible for. Overrides value
* given to `ToastProvider`.
*/
duration?: number;
onEscapeKeyDown?: DismissableLayerProps['onEscapeKeyDown'];
onPause?(): void;
onResume?(): void;
onSwipeStart?(event: SwipeEvent): void;
onSwipeMove?(event: SwipeEvent): void;
onSwipeCancel?(event: SwipeEvent): void;
onSwipeEnd?(event: SwipeEvent): void;
}
type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
interface ToastTitleProps extends PrimitiveDivProps {
}
declare const ToastTitle: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
interface ToastDescriptionProps extends PrimitiveDivProps {
}
declare const ToastDescription: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
interface ToastActionProps extends ToastCloseProps {
/**
* A short description for an alternate way to carry out the action. For screen reader users
* who will not be able to navigate to the button easily/quickly.
* @example <ToastAction altText="Goto account settings to upgrade">Upgrade</ToastAction>
* @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
*/
altText: string;
}
declare const ToastAction: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
interface ToastCloseProps extends PrimitiveButtonProps {
}
declare const ToastClose: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
declare const Provider: React.FC<ToastProviderProps>;
declare const Viewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
declare const Root: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
declare const Title: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
declare const Description: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
declare const Action: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
declare const Close: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
export { Action, Close, Description, Provider, Root, Title, Toast, ToastAction, type ToastActionProps, ToastClose, type ToastCloseProps, ToastDescription, type ToastDescriptionProps, type ToastProps, ToastProvider, type ToastProviderProps, ToastTitle, type ToastTitleProps, ToastViewport, type ToastViewportProps, Viewport, createToastScope };

120
node_modules/@radix-ui/react-toast/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,120 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import * as React from 'react';
import * as DismissableLayer from '@radix-ui/react-dismissable-layer';
import { Primitive } from '@radix-ui/react-primitive';
type SwipeDirection = 'up' | 'down' | 'left' | 'right';
declare const createToastScope: _radix_ui_react_context.CreateScope;
interface ToastProviderProps {
children?: React.ReactNode;
/**
* An author-localized label for each toast. Used to help screen reader users
* associate the interruption with a toast.
* @defaultValue 'Notification'
*/
label?: string;
/**
* Time in milliseconds that each toast should remain visible for.
* @defaultValue 5000
*/
duration?: number;
/**
* Direction of pointer swipe that should close the toast.
* @defaultValue 'right'
*/
swipeDirection?: SwipeDirection;
/**
* Distance in pixels that the swipe must pass before a close is triggered.
* @defaultValue 50
*/
swipeThreshold?: number;
}
declare const ToastProvider: React.FC<ToastProviderProps>;
type PrimitiveOrderedListProps = React.ComponentPropsWithoutRef<typeof Primitive.ol>;
interface ToastViewportProps extends PrimitiveOrderedListProps {
/**
* The keys to use as the keyboard shortcut that will move focus to the toast viewport.
* @defaultValue ['F8']
*/
hotkey?: string[];
/**
* An author-localized label for the toast viewport to provide context for screen reader users
* when navigating page landmarks. The available `{hotkey}` placeholder will be replaced for you.
* @defaultValue 'Notifications ({hotkey})'
*/
label?: string;
}
declare const ToastViewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
type ToastElement = ToastImplElement;
interface ToastProps extends Omit<ToastImplProps, keyof ToastImplPrivateProps> {
open?: boolean;
defaultOpen?: boolean;
onOpenChange?(open: boolean): void;
/**
* Used to force mounting when more control is needed. Useful when
* controlling animation with React animation libraries.
*/
forceMount?: true;
}
declare const Toast: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
type SwipeEvent = {
currentTarget: EventTarget & ToastElement;
} & Omit<CustomEvent<{
originalEvent: React.PointerEvent;
delta: {
x: number;
y: number;
};
}>, 'currentTarget'>;
type ToastImplElement = React.ComponentRef<typeof Primitive.li>;
type DismissableLayerProps = React.ComponentPropsWithoutRef<typeof DismissableLayer.Root>;
type ToastImplPrivateProps = {
open: boolean;
onClose(): void;
};
type PrimitiveListItemProps = React.ComponentPropsWithoutRef<typeof Primitive.li>;
interface ToastImplProps extends ToastImplPrivateProps, PrimitiveListItemProps {
type?: 'foreground' | 'background';
/**
* Time in milliseconds that toast should remain visible for. Overrides value
* given to `ToastProvider`.
*/
duration?: number;
onEscapeKeyDown?: DismissableLayerProps['onEscapeKeyDown'];
onPause?(): void;
onResume?(): void;
onSwipeStart?(event: SwipeEvent): void;
onSwipeMove?(event: SwipeEvent): void;
onSwipeCancel?(event: SwipeEvent): void;
onSwipeEnd?(event: SwipeEvent): void;
}
type PrimitiveDivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>;
interface ToastTitleProps extends PrimitiveDivProps {
}
declare const ToastTitle: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
interface ToastDescriptionProps extends PrimitiveDivProps {
}
declare const ToastDescription: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
interface ToastActionProps extends ToastCloseProps {
/**
* A short description for an alternate way to carry out the action. For screen reader users
* who will not be able to navigate to the button easily/quickly.
* @example <ToastAction altText="Goto account settings to upgrade">Upgrade</ToastAction>
* @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
*/
altText: string;
}
declare const ToastAction: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
interface ToastCloseProps extends PrimitiveButtonProps {
}
declare const ToastClose: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
declare const Provider: React.FC<ToastProviderProps>;
declare const Viewport: React.ForwardRefExoticComponent<ToastViewportProps & React.RefAttributes<HTMLOListElement>>;
declare const Root: React.ForwardRefExoticComponent<ToastProps & React.RefAttributes<HTMLLIElement>>;
declare const Title: React.ForwardRefExoticComponent<ToastTitleProps & React.RefAttributes<HTMLDivElement>>;
declare const Description: React.ForwardRefExoticComponent<ToastDescriptionProps & React.RefAttributes<HTMLDivElement>>;
declare const Action: React.ForwardRefExoticComponent<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
declare const Close: React.ForwardRefExoticComponent<ToastCloseProps & React.RefAttributes<HTMLButtonElement>>;
export { Action, Close, Description, Provider, Root, Title, Toast, ToastAction, type ToastActionProps, ToastClose, type ToastCloseProps, ToastDescription, type ToastDescriptionProps, type ToastProps, ToastProvider, type ToastProviderProps, ToastTitle, type ToastTitleProps, ToastViewport, type ToastViewportProps, Viewport, createToastScope };

677
node_modules/@radix-ui/react-toast/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,677 @@
"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);
// src/index.ts
var index_exports = {};
__export(index_exports, {
Action: () => Action,
Close: () => Close,
Description: () => Description,
Provider: () => Provider,
Root: () => Root2,
Title: () => Title,
Toast: () => Toast,
ToastAction: () => ToastAction,
ToastClose: () => ToastClose,
ToastDescription: () => ToastDescription,
ToastProvider: () => ToastProvider,
ToastTitle: () => ToastTitle,
ToastViewport: () => ToastViewport,
Viewport: () => Viewport,
createToastScope: () => createToastScope
});
module.exports = __toCommonJS(index_exports);
// src/toast.tsx
var React = __toESM(require("react"));
var ReactDOM = __toESM(require("react-dom"));
var import_primitive = require("@radix-ui/primitive");
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
var import_react_collection = require("@radix-ui/react-collection");
var import_react_context = require("@radix-ui/react-context");
var DismissableLayer = __toESM(require("@radix-ui/react-dismissable-layer"));
var import_react_portal = require("@radix-ui/react-portal");
var import_react_presence = require("@radix-ui/react-presence");
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_use_layout_effect = require("@radix-ui/react-use-layout-effect");
var import_react_visually_hidden = require("@radix-ui/react-visually-hidden");
var import_jsx_runtime = require("react/jsx-runtime");
var PROVIDER_NAME = "ToastProvider";
var [Collection, useCollection, createCollectionScope] = (0, import_react_collection.createCollection)("Toast");
var [createToastContext, createToastScope] = (0, import_react_context.createContextScope)("Toast", [createCollectionScope]);
var [ToastProviderProvider, useToastProviderContext] = createToastContext(PROVIDER_NAME);
var ToastProvider = (props) => {
const {
__scopeToast,
label = "Notification",
duration = 5e3,
swipeDirection = "right",
swipeThreshold = 50,
children
} = props;
const [viewport, setViewport] = React.useState(null);
const [toastCount, setToastCount] = React.useState(0);
const isFocusedToastEscapeKeyDownRef = React.useRef(false);
const isClosePausedRef = React.useRef(false);
if (!label.trim()) {
console.error(
`Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`
);
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Provider, { scope: __scopeToast, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
ToastProviderProvider,
{
scope: __scopeToast,
label,
duration,
swipeDirection,
swipeThreshold,
toastCount,
viewport,
onViewportChange: setViewport,
onToastAdd: React.useCallback(() => setToastCount((prevCount) => prevCount + 1), []),
onToastRemove: React.useCallback(() => setToastCount((prevCount) => prevCount - 1), []),
isFocusedToastEscapeKeyDownRef,
isClosePausedRef,
children
}
) });
};
ToastProvider.displayName = PROVIDER_NAME;
var VIEWPORT_NAME = "ToastViewport";
var VIEWPORT_DEFAULT_HOTKEY = ["F8"];
var VIEWPORT_PAUSE = "toast.viewportPause";
var VIEWPORT_RESUME = "toast.viewportResume";
var ToastViewport = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeToast,
hotkey = VIEWPORT_DEFAULT_HOTKEY,
label = "Notifications ({hotkey})",
...viewportProps
} = props;
const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast);
const getItems = useCollection(__scopeToast);
const wrapperRef = React.useRef(null);
const headFocusProxyRef = React.useRef(null);
const tailFocusProxyRef = React.useRef(null);
const ref = React.useRef(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref, context.onViewportChange);
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
const hasToasts = context.toastCount > 0;
React.useEffect(() => {
const handleKeyDown = (event) => {
const isHotkeyPressed = hotkey.length !== 0 && hotkey.every((key) => event[key] || event.code === key);
if (isHotkeyPressed) ref.current?.focus();
};
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [hotkey]);
React.useEffect(() => {
const wrapper = wrapperRef.current;
const viewport = ref.current;
if (hasToasts && wrapper && viewport) {
const handlePause = () => {
if (!context.isClosePausedRef.current) {
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
viewport.dispatchEvent(pauseEvent);
context.isClosePausedRef.current = true;
}
};
const handleResume = () => {
if (context.isClosePausedRef.current) {
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
viewport.dispatchEvent(resumeEvent);
context.isClosePausedRef.current = false;
}
};
const handleFocusOutResume = (event) => {
const isFocusMovingOutside = !wrapper.contains(event.relatedTarget);
if (isFocusMovingOutside) handleResume();
};
const handlePointerLeaveResume = () => {
const isFocusInside = wrapper.contains(document.activeElement);
if (!isFocusInside) handleResume();
};
wrapper.addEventListener("focusin", handlePause);
wrapper.addEventListener("focusout", handleFocusOutResume);
wrapper.addEventListener("pointermove", handlePause);
wrapper.addEventListener("pointerleave", handlePointerLeaveResume);
window.addEventListener("blur", handlePause);
window.addEventListener("focus", handleResume);
return () => {
wrapper.removeEventListener("focusin", handlePause);
wrapper.removeEventListener("focusout", handleFocusOutResume);
wrapper.removeEventListener("pointermove", handlePause);
wrapper.removeEventListener("pointerleave", handlePointerLeaveResume);
window.removeEventListener("blur", handlePause);
window.removeEventListener("focus", handleResume);
};
}
}, [hasToasts, context.isClosePausedRef]);
const getSortedTabbableCandidates = React.useCallback(
({ tabbingDirection }) => {
const toastItems = getItems();
const tabbableCandidates = toastItems.map((toastItem) => {
const toastNode = toastItem.ref.current;
const toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)];
return tabbingDirection === "forwards" ? toastTabbableCandidates : toastTabbableCandidates.reverse();
});
return (tabbingDirection === "forwards" ? tabbableCandidates.reverse() : tabbableCandidates).flat();
},
[getItems]
);
React.useEffect(() => {
const viewport = ref.current;
if (viewport) {
const handleKeyDown = (event) => {
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
const isTabKey = event.key === "Tab" && !isMetaKey;
if (isTabKey) {
const focusedElement = document.activeElement;
const isTabbingBackwards = event.shiftKey;
const targetIsViewport = event.target === viewport;
if (targetIsViewport && isTabbingBackwards) {
headFocusProxyRef.current?.focus();
return;
}
const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection });
const index = sortedCandidates.findIndex((candidate) => candidate === focusedElement);
if (focusFirst(sortedCandidates.slice(index + 1))) {
event.preventDefault();
} else {
isTabbingBackwards ? headFocusProxyRef.current?.focus() : tailFocusProxyRef.current?.focus();
}
}
};
viewport.addEventListener("keydown", handleKeyDown);
return () => viewport.removeEventListener("keydown", handleKeyDown);
}
}, [getItems, getSortedTabbableCandidates]);
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
DismissableLayer.Branch,
{
ref: wrapperRef,
role: "region",
"aria-label": label.replace("{hotkey}", hotkeyLabel),
tabIndex: -1,
style: { pointerEvents: hasToasts ? void 0 : "none" },
children: [
hasToasts && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
FocusProxy,
{
ref: headFocusProxyRef,
onFocusFromOutsideViewport: () => {
const tabbableCandidates = getSortedTabbableCandidates({
tabbingDirection: "forwards"
});
focusFirst(tabbableCandidates);
}
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.Slot, { scope: __scopeToast, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.ol, { tabIndex: -1, ...viewportProps, ref: composedRefs }) }),
hasToasts && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
FocusProxy,
{
ref: tailFocusProxyRef,
onFocusFromOutsideViewport: () => {
const tabbableCandidates = getSortedTabbableCandidates({
tabbingDirection: "backwards"
});
focusFirst(tabbableCandidates);
}
}
)
]
}
);
}
);
ToastViewport.displayName = VIEWPORT_NAME;
var FOCUS_PROXY_NAME = "ToastFocusProxy";
var FocusProxy = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props;
const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_visually_hidden.VisuallyHidden,
{
tabIndex: 0,
...proxyProps,
ref: forwardedRef,
style: { position: "fixed" },
onFocus: (event) => {
const prevFocusedElement = event.relatedTarget;
const isFocusFromOutsideViewport = !context.viewport?.contains(prevFocusedElement);
if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
}
}
);
}
);
FocusProxy.displayName = FOCUS_PROXY_NAME;
var TOAST_NAME = "Toast";
var TOAST_SWIPE_START = "toast.swipeStart";
var TOAST_SWIPE_MOVE = "toast.swipeMove";
var TOAST_SWIPE_CANCEL = "toast.swipeCancel";
var TOAST_SWIPE_END = "toast.swipeEnd";
var Toast = React.forwardRef(
(props, forwardedRef) => {
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
const [open, setOpen] = (0, import_react_use_controllable_state.useControllableState)({
prop: openProp,
defaultProp: defaultOpen ?? true,
onChange: onOpenChange,
caller: TOAST_NAME
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_presence.Presence, { present: forceMount || open, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
ToastImpl,
{
open,
...toastProps,
ref: forwardedRef,
onClose: () => setOpen(false),
onPause: (0, import_react_use_callback_ref.useCallbackRef)(props.onPause),
onResume: (0, import_react_use_callback_ref.useCallbackRef)(props.onResume),
onSwipeStart: (0, import_primitive.composeEventHandlers)(props.onSwipeStart, (event) => {
event.currentTarget.setAttribute("data-swipe", "start");
}),
onSwipeMove: (0, import_primitive.composeEventHandlers)(props.onSwipeMove, (event) => {
const { x, y } = event.detail.delta;
event.currentTarget.setAttribute("data-swipe", "move");
event.currentTarget.style.setProperty("--radix-toast-swipe-move-x", `${x}px`);
event.currentTarget.style.setProperty("--radix-toast-swipe-move-y", `${y}px`);
}),
onSwipeCancel: (0, import_primitive.composeEventHandlers)(props.onSwipeCancel, (event) => {
event.currentTarget.setAttribute("data-swipe", "cancel");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-x");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-y");
event.currentTarget.style.removeProperty("--radix-toast-swipe-end-x");
event.currentTarget.style.removeProperty("--radix-toast-swipe-end-y");
}),
onSwipeEnd: (0, import_primitive.composeEventHandlers)(props.onSwipeEnd, (event) => {
const { x, y } = event.detail.delta;
event.currentTarget.setAttribute("data-swipe", "end");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-x");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-y");
event.currentTarget.style.setProperty("--radix-toast-swipe-end-x", `${x}px`);
event.currentTarget.style.setProperty("--radix-toast-swipe-end-y", `${y}px`);
setOpen(false);
})
}
) });
}
);
Toast.displayName = TOAST_NAME;
var [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(TOAST_NAME, {
onClose() {
}
});
var ToastImpl = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeToast,
type = "foreground",
duration: durationProp,
open,
onClose,
onEscapeKeyDown,
onPause,
onResume,
onSwipeStart,
onSwipeMove,
onSwipeCancel,
onSwipeEnd,
...toastProps
} = props;
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
const [node, setNode] = React.useState(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node2) => setNode(node2));
const pointerStartRef = React.useRef(null);
const swipeDeltaRef = React.useRef(null);
const duration = durationProp || context.duration;
const closeTimerStartTimeRef = React.useRef(0);
const closeTimerRemainingTimeRef = React.useRef(duration);
const closeTimerRef = React.useRef(0);
const { onToastAdd, onToastRemove } = context;
const handleClose = (0, import_react_use_callback_ref.useCallbackRef)(() => {
const isFocusInToast = node?.contains(document.activeElement);
if (isFocusInToast) context.viewport?.focus();
onClose();
});
const startTimer = React.useCallback(
(duration2) => {
if (!duration2 || duration2 === Infinity) return;
window.clearTimeout(closeTimerRef.current);
closeTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
closeTimerRef.current = window.setTimeout(handleClose, duration2);
},
[handleClose]
);
React.useEffect(() => {
const viewport = context.viewport;
if (viewport) {
const handleResume = () => {
startTimer(closeTimerRemainingTimeRef.current);
onResume?.();
};
const handlePause = () => {
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef.current;
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
window.clearTimeout(closeTimerRef.current);
onPause?.();
};
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
return () => {
viewport.removeEventListener(VIEWPORT_PAUSE, handlePause);
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
};
}
}, [context.viewport, duration, onPause, onResume, startTimer]);
React.useEffect(() => {
if (open && !context.isClosePausedRef.current) startTimer(duration);
}, [open, duration, context.isClosePausedRef, startTimer]);
React.useEffect(() => {
onToastAdd();
return () => onToastRemove();
}, [onToastAdd, onToastRemove]);
const announceTextContent = React.useMemo(() => {
return node ? getAnnounceTextContent(node) : null;
}, [node]);
if (!context.viewport) return null;
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
announceTextContent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
ToastAnnounce,
{
__scopeToast,
role: "status",
"aria-live": type === "foreground" ? "assertive" : "polite",
children: announceTextContent
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastInteractiveProvider, { scope: __scopeToast, onClose: handleClose, children: ReactDOM.createPortal(
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Collection.ItemSlot, { scope: __scopeToast, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
DismissableLayer.Root,
{
asChild: true,
onEscapeKeyDown: (0, import_primitive.composeEventHandlers)(onEscapeKeyDown, () => {
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
context.isFocusedToastEscapeKeyDownRef.current = false;
}),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.li,
{
tabIndex: 0,
"data-state": open ? "open" : "closed",
"data-swipe-direction": context.swipeDirection,
...toastProps,
ref: composedRefs,
style: { userSelect: "none", touchAction: "none", ...props.style },
onKeyDown: (0, import_primitive.composeEventHandlers)(props.onKeyDown, (event) => {
if (event.key !== "Escape") return;
onEscapeKeyDown?.(event.nativeEvent);
if (!event.nativeEvent.defaultPrevented) {
context.isFocusedToastEscapeKeyDownRef.current = true;
handleClose();
}
}),
onPointerDown: (0, import_primitive.composeEventHandlers)(props.onPointerDown, (event) => {
if (event.button !== 0) return;
pointerStartRef.current = { x: event.clientX, y: event.clientY };
}),
onPointerMove: (0, import_primitive.composeEventHandlers)(props.onPointerMove, (event) => {
if (!pointerStartRef.current) return;
const x = event.clientX - pointerStartRef.current.x;
const y = event.clientY - pointerStartRef.current.y;
const hasSwipeMoveStarted = Boolean(swipeDeltaRef.current);
const isHorizontalSwipe = ["left", "right"].includes(context.swipeDirection);
const clamp = ["left", "up"].includes(context.swipeDirection) ? Math.min : Math.max;
const clampedX = isHorizontalSwipe ? clamp(0, x) : 0;
const clampedY = !isHorizontalSwipe ? clamp(0, y) : 0;
const moveStartBuffer = event.pointerType === "touch" ? 10 : 2;
const delta = { x: clampedX, y: clampedY };
const eventDetail = { originalEvent: event, delta };
if (hasSwipeMoveStarted) {
swipeDeltaRef.current = delta;
handleAndDispatchCustomEvent(TOAST_SWIPE_MOVE, onSwipeMove, eventDetail, {
discrete: false
});
} else if (isDeltaInDirection(delta, context.swipeDirection, moveStartBuffer)) {
swipeDeltaRef.current = delta;
handleAndDispatchCustomEvent(TOAST_SWIPE_START, onSwipeStart, eventDetail, {
discrete: false
});
event.target.setPointerCapture(event.pointerId);
} else if (Math.abs(x) > moveStartBuffer || Math.abs(y) > moveStartBuffer) {
pointerStartRef.current = null;
}
}),
onPointerUp: (0, import_primitive.composeEventHandlers)(props.onPointerUp, (event) => {
const delta = swipeDeltaRef.current;
const target = event.target;
if (target.hasPointerCapture(event.pointerId)) {
target.releasePointerCapture(event.pointerId);
}
swipeDeltaRef.current = null;
pointerStartRef.current = null;
if (delta) {
const toast = event.currentTarget;
const eventDetail = { originalEvent: event, delta };
if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {
handleAndDispatchCustomEvent(TOAST_SWIPE_END, onSwipeEnd, eventDetail, {
discrete: true
});
} else {
handleAndDispatchCustomEvent(
TOAST_SWIPE_CANCEL,
onSwipeCancel,
eventDetail,
{
discrete: true
}
);
}
toast.addEventListener("click", (event2) => event2.preventDefault(), {
once: true
});
}
})
}
)
}
) }),
context.viewport
) })
] });
}
);
var ToastAnnounce = (props) => {
const { __scopeToast, children, ...announceProps } = props;
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
const [renderAnnounceText, setRenderAnnounceText] = React.useState(false);
const [isAnnounced, setIsAnnounced] = React.useState(false);
useNextFrame(() => setRenderAnnounceText(true));
React.useEffect(() => {
const timer = window.setTimeout(() => setIsAnnounced(true), 1e3);
return () => window.clearTimeout(timer);
}, []);
return isAnnounced ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_portal.Portal, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_visually_hidden.VisuallyHidden, { ...announceProps, children: renderAnnounceText && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
context.label,
" ",
children
] }) }) });
};
var TITLE_NAME = "ToastTitle";
var ToastTitle = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, ...titleProps } = props;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...titleProps, ref: forwardedRef });
}
);
ToastTitle.displayName = TITLE_NAME;
var DESCRIPTION_NAME = "ToastDescription";
var ToastDescription = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, ...descriptionProps } = props;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.div, { ...descriptionProps, ref: forwardedRef });
}
);
ToastDescription.displayName = DESCRIPTION_NAME;
var ACTION_NAME = "ToastAction";
var ToastAction = React.forwardRef(
(props, forwardedRef) => {
const { altText, ...actionProps } = props;
if (!altText.trim()) {
console.error(
`Invalid prop \`altText\` supplied to \`${ACTION_NAME}\`. Expected non-empty \`string\`.`
);
return null;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastAnnounceExclude, { altText, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastClose, { ...actionProps, ref: forwardedRef }) });
}
);
ToastAction.displayName = ACTION_NAME;
var CLOSE_NAME = "ToastClose";
var ToastClose = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, ...closeProps } = props;
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ToastAnnounceExclude, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.button,
{
type: "button",
...closeProps,
ref: forwardedRef,
onClick: (0, import_primitive.composeEventHandlers)(props.onClick, interactiveContext.onClose)
}
) });
}
);
ToastClose.displayName = CLOSE_NAME;
var ToastAnnounceExclude = React.forwardRef((props, forwardedRef) => {
const { __scopeToast, altText, ...announceExcludeProps } = props;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.div,
{
"data-radix-toast-announce-exclude": "",
"data-radix-toast-announce-alt": altText || void 0,
...announceExcludeProps,
ref: forwardedRef
}
);
});
function getAnnounceTextContent(container) {
const textContent = [];
const childNodes = Array.from(container.childNodes);
childNodes.forEach((node) => {
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
if (isHTMLElement(node)) {
const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
const isExcluded = node.dataset.radixToastAnnounceExclude === "";
if (!isHidden) {
if (isExcluded) {
const altText = node.dataset.radixToastAnnounceAlt;
if (altText) textContent.push(altText);
} else {
textContent.push(...getAnnounceTextContent(node));
}
}
}
});
return textContent;
}
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
const currentTarget = detail.originalEvent.currentTarget;
const event = new CustomEvent(name, { bubbles: true, cancelable: true, detail });
if (handler) currentTarget.addEventListener(name, handler, { once: true });
if (discrete) {
(0, import_react_primitive.dispatchDiscreteCustomEvent)(currentTarget, event);
} else {
currentTarget.dispatchEvent(event);
}
}
var isDeltaInDirection = (delta, direction, threshold = 0) => {
const deltaX = Math.abs(delta.x);
const deltaY = Math.abs(delta.y);
const isDeltaX = deltaX > deltaY;
if (direction === "left" || direction === "right") {
return isDeltaX && deltaX > threshold;
} else {
return !isDeltaX && deltaY > threshold;
}
};
function useNextFrame(callback = () => {
}) {
const fn = (0, import_react_use_callback_ref.useCallbackRef)(callback);
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
let raf1 = 0;
let raf2 = 0;
raf1 = window.requestAnimationFrame(() => raf2 = window.requestAnimationFrame(fn));
return () => {
window.cancelAnimationFrame(raf1);
window.cancelAnimationFrame(raf2);
};
}, [fn]);
}
function isHTMLElement(node) {
return node.nodeType === node.ELEMENT_NODE;
}
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 focusFirst(candidates) {
const previouslyFocusedElement = document.activeElement;
return candidates.some((candidate) => {
if (candidate === previouslyFocusedElement) return true;
candidate.focus();
return document.activeElement !== previouslyFocusedElement;
});
}
var Provider = ToastProvider;
var Viewport = ToastViewport;
var Root2 = Toast;
var Title = ToastTitle;
var Description = ToastDescription;
var Action = ToastAction;
var Close = ToastClose;
//# sourceMappingURL=index.js.map

7
node_modules/@radix-ui/react-toast/dist/index.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

645
node_modules/@radix-ui/react-toast/dist/index.mjs generated vendored Normal file
View file

@ -0,0 +1,645 @@
"use client";
// src/toast.tsx
import * as React from "react";
import * as ReactDOM from "react-dom";
import { composeEventHandlers } from "@radix-ui/primitive";
import { useComposedRefs } from "@radix-ui/react-compose-refs";
import { createCollection } from "@radix-ui/react-collection";
import { createContextScope } from "@radix-ui/react-context";
import * as DismissableLayer from "@radix-ui/react-dismissable-layer";
import { Portal } from "@radix-ui/react-portal";
import { Presence } from "@radix-ui/react-presence";
import { Primitive, dispatchDiscreteCustomEvent } from "@radix-ui/react-primitive";
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
import { useControllableState } from "@radix-ui/react-use-controllable-state";
import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
import { VisuallyHidden } from "@radix-ui/react-visually-hidden";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var PROVIDER_NAME = "ToastProvider";
var [Collection, useCollection, createCollectionScope] = createCollection("Toast");
var [createToastContext, createToastScope] = createContextScope("Toast", [createCollectionScope]);
var [ToastProviderProvider, useToastProviderContext] = createToastContext(PROVIDER_NAME);
var ToastProvider = (props) => {
const {
__scopeToast,
label = "Notification",
duration = 5e3,
swipeDirection = "right",
swipeThreshold = 50,
children
} = props;
const [viewport, setViewport] = React.useState(null);
const [toastCount, setToastCount] = React.useState(0);
const isFocusedToastEscapeKeyDownRef = React.useRef(false);
const isClosePausedRef = React.useRef(false);
if (!label.trim()) {
console.error(
`Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`
);
}
return /* @__PURE__ */ jsx(Collection.Provider, { scope: __scopeToast, children: /* @__PURE__ */ jsx(
ToastProviderProvider,
{
scope: __scopeToast,
label,
duration,
swipeDirection,
swipeThreshold,
toastCount,
viewport,
onViewportChange: setViewport,
onToastAdd: React.useCallback(() => setToastCount((prevCount) => prevCount + 1), []),
onToastRemove: React.useCallback(() => setToastCount((prevCount) => prevCount - 1), []),
isFocusedToastEscapeKeyDownRef,
isClosePausedRef,
children
}
) });
};
ToastProvider.displayName = PROVIDER_NAME;
var VIEWPORT_NAME = "ToastViewport";
var VIEWPORT_DEFAULT_HOTKEY = ["F8"];
var VIEWPORT_PAUSE = "toast.viewportPause";
var VIEWPORT_RESUME = "toast.viewportResume";
var ToastViewport = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeToast,
hotkey = VIEWPORT_DEFAULT_HOTKEY,
label = "Notifications ({hotkey})",
...viewportProps
} = props;
const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast);
const getItems = useCollection(__scopeToast);
const wrapperRef = React.useRef(null);
const headFocusProxyRef = React.useRef(null);
const tailFocusProxyRef = React.useRef(null);
const ref = React.useRef(null);
const composedRefs = useComposedRefs(forwardedRef, ref, context.onViewportChange);
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
const hasToasts = context.toastCount > 0;
React.useEffect(() => {
const handleKeyDown = (event) => {
const isHotkeyPressed = hotkey.length !== 0 && hotkey.every((key) => event[key] || event.code === key);
if (isHotkeyPressed) ref.current?.focus();
};
document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [hotkey]);
React.useEffect(() => {
const wrapper = wrapperRef.current;
const viewport = ref.current;
if (hasToasts && wrapper && viewport) {
const handlePause = () => {
if (!context.isClosePausedRef.current) {
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
viewport.dispatchEvent(pauseEvent);
context.isClosePausedRef.current = true;
}
};
const handleResume = () => {
if (context.isClosePausedRef.current) {
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
viewport.dispatchEvent(resumeEvent);
context.isClosePausedRef.current = false;
}
};
const handleFocusOutResume = (event) => {
const isFocusMovingOutside = !wrapper.contains(event.relatedTarget);
if (isFocusMovingOutside) handleResume();
};
const handlePointerLeaveResume = () => {
const isFocusInside = wrapper.contains(document.activeElement);
if (!isFocusInside) handleResume();
};
wrapper.addEventListener("focusin", handlePause);
wrapper.addEventListener("focusout", handleFocusOutResume);
wrapper.addEventListener("pointermove", handlePause);
wrapper.addEventListener("pointerleave", handlePointerLeaveResume);
window.addEventListener("blur", handlePause);
window.addEventListener("focus", handleResume);
return () => {
wrapper.removeEventListener("focusin", handlePause);
wrapper.removeEventListener("focusout", handleFocusOutResume);
wrapper.removeEventListener("pointermove", handlePause);
wrapper.removeEventListener("pointerleave", handlePointerLeaveResume);
window.removeEventListener("blur", handlePause);
window.removeEventListener("focus", handleResume);
};
}
}, [hasToasts, context.isClosePausedRef]);
const getSortedTabbableCandidates = React.useCallback(
({ tabbingDirection }) => {
const toastItems = getItems();
const tabbableCandidates = toastItems.map((toastItem) => {
const toastNode = toastItem.ref.current;
const toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)];
return tabbingDirection === "forwards" ? toastTabbableCandidates : toastTabbableCandidates.reverse();
});
return (tabbingDirection === "forwards" ? tabbableCandidates.reverse() : tabbableCandidates).flat();
},
[getItems]
);
React.useEffect(() => {
const viewport = ref.current;
if (viewport) {
const handleKeyDown = (event) => {
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
const isTabKey = event.key === "Tab" && !isMetaKey;
if (isTabKey) {
const focusedElement = document.activeElement;
const isTabbingBackwards = event.shiftKey;
const targetIsViewport = event.target === viewport;
if (targetIsViewport && isTabbingBackwards) {
headFocusProxyRef.current?.focus();
return;
}
const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection });
const index = sortedCandidates.findIndex((candidate) => candidate === focusedElement);
if (focusFirst(sortedCandidates.slice(index + 1))) {
event.preventDefault();
} else {
isTabbingBackwards ? headFocusProxyRef.current?.focus() : tailFocusProxyRef.current?.focus();
}
}
};
viewport.addEventListener("keydown", handleKeyDown);
return () => viewport.removeEventListener("keydown", handleKeyDown);
}
}, [getItems, getSortedTabbableCandidates]);
return /* @__PURE__ */ jsxs(
DismissableLayer.Branch,
{
ref: wrapperRef,
role: "region",
"aria-label": label.replace("{hotkey}", hotkeyLabel),
tabIndex: -1,
style: { pointerEvents: hasToasts ? void 0 : "none" },
children: [
hasToasts && /* @__PURE__ */ jsx(
FocusProxy,
{
ref: headFocusProxyRef,
onFocusFromOutsideViewport: () => {
const tabbableCandidates = getSortedTabbableCandidates({
tabbingDirection: "forwards"
});
focusFirst(tabbableCandidates);
}
}
),
/* @__PURE__ */ jsx(Collection.Slot, { scope: __scopeToast, children: /* @__PURE__ */ jsx(Primitive.ol, { tabIndex: -1, ...viewportProps, ref: composedRefs }) }),
hasToasts && /* @__PURE__ */ jsx(
FocusProxy,
{
ref: tailFocusProxyRef,
onFocusFromOutsideViewport: () => {
const tabbableCandidates = getSortedTabbableCandidates({
tabbingDirection: "backwards"
});
focusFirst(tabbableCandidates);
}
}
)
]
}
);
}
);
ToastViewport.displayName = VIEWPORT_NAME;
var FOCUS_PROXY_NAME = "ToastFocusProxy";
var FocusProxy = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props;
const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast);
return /* @__PURE__ */ jsx(
VisuallyHidden,
{
tabIndex: 0,
...proxyProps,
ref: forwardedRef,
style: { position: "fixed" },
onFocus: (event) => {
const prevFocusedElement = event.relatedTarget;
const isFocusFromOutsideViewport = !context.viewport?.contains(prevFocusedElement);
if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
}
}
);
}
);
FocusProxy.displayName = FOCUS_PROXY_NAME;
var TOAST_NAME = "Toast";
var TOAST_SWIPE_START = "toast.swipeStart";
var TOAST_SWIPE_MOVE = "toast.swipeMove";
var TOAST_SWIPE_CANCEL = "toast.swipeCancel";
var TOAST_SWIPE_END = "toast.swipeEnd";
var Toast = React.forwardRef(
(props, forwardedRef) => {
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
const [open, setOpen] = useControllableState({
prop: openProp,
defaultProp: defaultOpen ?? true,
onChange: onOpenChange,
caller: TOAST_NAME
});
return /* @__PURE__ */ jsx(Presence, { present: forceMount || open, children: /* @__PURE__ */ jsx(
ToastImpl,
{
open,
...toastProps,
ref: forwardedRef,
onClose: () => setOpen(false),
onPause: useCallbackRef(props.onPause),
onResume: useCallbackRef(props.onResume),
onSwipeStart: composeEventHandlers(props.onSwipeStart, (event) => {
event.currentTarget.setAttribute("data-swipe", "start");
}),
onSwipeMove: composeEventHandlers(props.onSwipeMove, (event) => {
const { x, y } = event.detail.delta;
event.currentTarget.setAttribute("data-swipe", "move");
event.currentTarget.style.setProperty("--radix-toast-swipe-move-x", `${x}px`);
event.currentTarget.style.setProperty("--radix-toast-swipe-move-y", `${y}px`);
}),
onSwipeCancel: composeEventHandlers(props.onSwipeCancel, (event) => {
event.currentTarget.setAttribute("data-swipe", "cancel");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-x");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-y");
event.currentTarget.style.removeProperty("--radix-toast-swipe-end-x");
event.currentTarget.style.removeProperty("--radix-toast-swipe-end-y");
}),
onSwipeEnd: composeEventHandlers(props.onSwipeEnd, (event) => {
const { x, y } = event.detail.delta;
event.currentTarget.setAttribute("data-swipe", "end");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-x");
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-y");
event.currentTarget.style.setProperty("--radix-toast-swipe-end-x", `${x}px`);
event.currentTarget.style.setProperty("--radix-toast-swipe-end-y", `${y}px`);
setOpen(false);
})
}
) });
}
);
Toast.displayName = TOAST_NAME;
var [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(TOAST_NAME, {
onClose() {
}
});
var ToastImpl = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeToast,
type = "foreground",
duration: durationProp,
open,
onClose,
onEscapeKeyDown,
onPause,
onResume,
onSwipeStart,
onSwipeMove,
onSwipeCancel,
onSwipeEnd,
...toastProps
} = props;
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
const [node, setNode] = React.useState(null);
const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
const pointerStartRef = React.useRef(null);
const swipeDeltaRef = React.useRef(null);
const duration = durationProp || context.duration;
const closeTimerStartTimeRef = React.useRef(0);
const closeTimerRemainingTimeRef = React.useRef(duration);
const closeTimerRef = React.useRef(0);
const { onToastAdd, onToastRemove } = context;
const handleClose = useCallbackRef(() => {
const isFocusInToast = node?.contains(document.activeElement);
if (isFocusInToast) context.viewport?.focus();
onClose();
});
const startTimer = React.useCallback(
(duration2) => {
if (!duration2 || duration2 === Infinity) return;
window.clearTimeout(closeTimerRef.current);
closeTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
closeTimerRef.current = window.setTimeout(handleClose, duration2);
},
[handleClose]
);
React.useEffect(() => {
const viewport = context.viewport;
if (viewport) {
const handleResume = () => {
startTimer(closeTimerRemainingTimeRef.current);
onResume?.();
};
const handlePause = () => {
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef.current;
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
window.clearTimeout(closeTimerRef.current);
onPause?.();
};
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
return () => {
viewport.removeEventListener(VIEWPORT_PAUSE, handlePause);
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
};
}
}, [context.viewport, duration, onPause, onResume, startTimer]);
React.useEffect(() => {
if (open && !context.isClosePausedRef.current) startTimer(duration);
}, [open, duration, context.isClosePausedRef, startTimer]);
React.useEffect(() => {
onToastAdd();
return () => onToastRemove();
}, [onToastAdd, onToastRemove]);
const announceTextContent = React.useMemo(() => {
return node ? getAnnounceTextContent(node) : null;
}, [node]);
if (!context.viewport) return null;
return /* @__PURE__ */ jsxs(Fragment, { children: [
announceTextContent && /* @__PURE__ */ jsx(
ToastAnnounce,
{
__scopeToast,
role: "status",
"aria-live": type === "foreground" ? "assertive" : "polite",
children: announceTextContent
}
),
/* @__PURE__ */ jsx(ToastInteractiveProvider, { scope: __scopeToast, onClose: handleClose, children: ReactDOM.createPortal(
/* @__PURE__ */ jsx(Collection.ItemSlot, { scope: __scopeToast, children: /* @__PURE__ */ jsx(
DismissableLayer.Root,
{
asChild: true,
onEscapeKeyDown: composeEventHandlers(onEscapeKeyDown, () => {
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
context.isFocusedToastEscapeKeyDownRef.current = false;
}),
children: /* @__PURE__ */ jsx(
Primitive.li,
{
tabIndex: 0,
"data-state": open ? "open" : "closed",
"data-swipe-direction": context.swipeDirection,
...toastProps,
ref: composedRefs,
style: { userSelect: "none", touchAction: "none", ...props.style },
onKeyDown: composeEventHandlers(props.onKeyDown, (event) => {
if (event.key !== "Escape") return;
onEscapeKeyDown?.(event.nativeEvent);
if (!event.nativeEvent.defaultPrevented) {
context.isFocusedToastEscapeKeyDownRef.current = true;
handleClose();
}
}),
onPointerDown: composeEventHandlers(props.onPointerDown, (event) => {
if (event.button !== 0) return;
pointerStartRef.current = { x: event.clientX, y: event.clientY };
}),
onPointerMove: composeEventHandlers(props.onPointerMove, (event) => {
if (!pointerStartRef.current) return;
const x = event.clientX - pointerStartRef.current.x;
const y = event.clientY - pointerStartRef.current.y;
const hasSwipeMoveStarted = Boolean(swipeDeltaRef.current);
const isHorizontalSwipe = ["left", "right"].includes(context.swipeDirection);
const clamp = ["left", "up"].includes(context.swipeDirection) ? Math.min : Math.max;
const clampedX = isHorizontalSwipe ? clamp(0, x) : 0;
const clampedY = !isHorizontalSwipe ? clamp(0, y) : 0;
const moveStartBuffer = event.pointerType === "touch" ? 10 : 2;
const delta = { x: clampedX, y: clampedY };
const eventDetail = { originalEvent: event, delta };
if (hasSwipeMoveStarted) {
swipeDeltaRef.current = delta;
handleAndDispatchCustomEvent(TOAST_SWIPE_MOVE, onSwipeMove, eventDetail, {
discrete: false
});
} else if (isDeltaInDirection(delta, context.swipeDirection, moveStartBuffer)) {
swipeDeltaRef.current = delta;
handleAndDispatchCustomEvent(TOAST_SWIPE_START, onSwipeStart, eventDetail, {
discrete: false
});
event.target.setPointerCapture(event.pointerId);
} else if (Math.abs(x) > moveStartBuffer || Math.abs(y) > moveStartBuffer) {
pointerStartRef.current = null;
}
}),
onPointerUp: composeEventHandlers(props.onPointerUp, (event) => {
const delta = swipeDeltaRef.current;
const target = event.target;
if (target.hasPointerCapture(event.pointerId)) {
target.releasePointerCapture(event.pointerId);
}
swipeDeltaRef.current = null;
pointerStartRef.current = null;
if (delta) {
const toast = event.currentTarget;
const eventDetail = { originalEvent: event, delta };
if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {
handleAndDispatchCustomEvent(TOAST_SWIPE_END, onSwipeEnd, eventDetail, {
discrete: true
});
} else {
handleAndDispatchCustomEvent(
TOAST_SWIPE_CANCEL,
onSwipeCancel,
eventDetail,
{
discrete: true
}
);
}
toast.addEventListener("click", (event2) => event2.preventDefault(), {
once: true
});
}
})
}
)
}
) }),
context.viewport
) })
] });
}
);
var ToastAnnounce = (props) => {
const { __scopeToast, children, ...announceProps } = props;
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
const [renderAnnounceText, setRenderAnnounceText] = React.useState(false);
const [isAnnounced, setIsAnnounced] = React.useState(false);
useNextFrame(() => setRenderAnnounceText(true));
React.useEffect(() => {
const timer = window.setTimeout(() => setIsAnnounced(true), 1e3);
return () => window.clearTimeout(timer);
}, []);
return isAnnounced ? null : /* @__PURE__ */ jsx(Portal, { asChild: true, children: /* @__PURE__ */ jsx(VisuallyHidden, { ...announceProps, children: renderAnnounceText && /* @__PURE__ */ jsxs(Fragment, { children: [
context.label,
" ",
children
] }) }) });
};
var TITLE_NAME = "ToastTitle";
var ToastTitle = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, ...titleProps } = props;
return /* @__PURE__ */ jsx(Primitive.div, { ...titleProps, ref: forwardedRef });
}
);
ToastTitle.displayName = TITLE_NAME;
var DESCRIPTION_NAME = "ToastDescription";
var ToastDescription = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, ...descriptionProps } = props;
return /* @__PURE__ */ jsx(Primitive.div, { ...descriptionProps, ref: forwardedRef });
}
);
ToastDescription.displayName = DESCRIPTION_NAME;
var ACTION_NAME = "ToastAction";
var ToastAction = React.forwardRef(
(props, forwardedRef) => {
const { altText, ...actionProps } = props;
if (!altText.trim()) {
console.error(
`Invalid prop \`altText\` supplied to \`${ACTION_NAME}\`. Expected non-empty \`string\`.`
);
return null;
}
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { altText, asChild: true, children: /* @__PURE__ */ jsx(ToastClose, { ...actionProps, ref: forwardedRef }) });
}
);
ToastAction.displayName = ACTION_NAME;
var CLOSE_NAME = "ToastClose";
var ToastClose = React.forwardRef(
(props, forwardedRef) => {
const { __scopeToast, ...closeProps } = props;
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { asChild: true, children: /* @__PURE__ */ jsx(
Primitive.button,
{
type: "button",
...closeProps,
ref: forwardedRef,
onClick: composeEventHandlers(props.onClick, interactiveContext.onClose)
}
) });
}
);
ToastClose.displayName = CLOSE_NAME;
var ToastAnnounceExclude = React.forwardRef((props, forwardedRef) => {
const { __scopeToast, altText, ...announceExcludeProps } = props;
return /* @__PURE__ */ jsx(
Primitive.div,
{
"data-radix-toast-announce-exclude": "",
"data-radix-toast-announce-alt": altText || void 0,
...announceExcludeProps,
ref: forwardedRef
}
);
});
function getAnnounceTextContent(container) {
const textContent = [];
const childNodes = Array.from(container.childNodes);
childNodes.forEach((node) => {
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
if (isHTMLElement(node)) {
const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
const isExcluded = node.dataset.radixToastAnnounceExclude === "";
if (!isHidden) {
if (isExcluded) {
const altText = node.dataset.radixToastAnnounceAlt;
if (altText) textContent.push(altText);
} else {
textContent.push(...getAnnounceTextContent(node));
}
}
}
});
return textContent;
}
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
const currentTarget = detail.originalEvent.currentTarget;
const event = new CustomEvent(name, { bubbles: true, cancelable: true, detail });
if (handler) currentTarget.addEventListener(name, handler, { once: true });
if (discrete) {
dispatchDiscreteCustomEvent(currentTarget, event);
} else {
currentTarget.dispatchEvent(event);
}
}
var isDeltaInDirection = (delta, direction, threshold = 0) => {
const deltaX = Math.abs(delta.x);
const deltaY = Math.abs(delta.y);
const isDeltaX = deltaX > deltaY;
if (direction === "left" || direction === "right") {
return isDeltaX && deltaX > threshold;
} else {
return !isDeltaX && deltaY > threshold;
}
};
function useNextFrame(callback = () => {
}) {
const fn = useCallbackRef(callback);
useLayoutEffect(() => {
let raf1 = 0;
let raf2 = 0;
raf1 = window.requestAnimationFrame(() => raf2 = window.requestAnimationFrame(fn));
return () => {
window.cancelAnimationFrame(raf1);
window.cancelAnimationFrame(raf2);
};
}, [fn]);
}
function isHTMLElement(node) {
return node.nodeType === node.ELEMENT_NODE;
}
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 focusFirst(candidates) {
const previouslyFocusedElement = document.activeElement;
return candidates.some((candidate) => {
if (candidate === previouslyFocusedElement) return true;
candidate.focus();
return document.activeElement !== previouslyFocusedElement;
});
}
var Provider = ToastProvider;
var Viewport = ToastViewport;
var Root2 = Toast;
var Title = ToastTitle;
var Description = ToastDescription;
var Action = ToastAction;
var Close = ToastClose;
export {
Action,
Close,
Description,
Provider,
Root2 as Root,
Title,
Toast,
ToastAction,
ToastClose,
ToastDescription,
ToastProvider,
ToastTitle,
ToastViewport,
Viewport,
createToastScope
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,3 @@
# `primitive`
This is an internal utility, not intended for public usage.

View file

@ -0,0 +1,20 @@
declare const canUseDOM: boolean;
declare function composeEventHandlers<E extends {
defaultPrevented: boolean;
}>(originalEventHandler?: (event: E) => void, ourEventHandler?: (event: E) => void, { checkForDefaultPrevented }?: {
checkForDefaultPrevented?: boolean | undefined;
}): (event: E) => void;
declare function getOwnerWindow(element: Node | null | undefined): Window & typeof globalThis;
declare function getOwnerDocument(element: Node | null | undefined): Document;
/**
* Lifted from https://github.com/ariakit/ariakit/blob/main/packages/ariakit-core/src/utils/dom.ts#L37
* MIT License, Copyright (c) AriaKit.
*/
declare function getActiveElement(node: Node | null | undefined, activeDescendant?: boolean): HTMLElement | null;
declare function isFrame(element: Element): element is HTMLIFrameElement;
type Timeout = ReturnType<typeof setTimeout>;
type Interval = ReturnType<typeof setInterval>;
type Immediate = ReturnType<typeof setImmediate>;
export { type Immediate, type Interval, type Timeout, canUseDOM, composeEventHandlers, getActiveElement, getOwnerDocument, getOwnerWindow, isFrame };

View file

@ -0,0 +1,20 @@
declare const canUseDOM: boolean;
declare function composeEventHandlers<E extends {
defaultPrevented: boolean;
}>(originalEventHandler?: (event: E) => void, ourEventHandler?: (event: E) => void, { checkForDefaultPrevented }?: {
checkForDefaultPrevented?: boolean | undefined;
}): (event: E) => void;
declare function getOwnerWindow(element: Node | null | undefined): Window & typeof globalThis;
declare function getOwnerDocument(element: Node | null | undefined): Document;
/**
* Lifted from https://github.com/ariakit/ariakit/blob/main/packages/ariakit-core/src/utils/dom.ts#L37
* MIT License, Copyright (c) AriaKit.
*/
declare function getActiveElement(node: Node | null | undefined, activeDescendant?: boolean): HTMLElement | null;
declare function isFrame(element: Element): element is HTMLIFrameElement;
type Timeout = ReturnType<typeof setTimeout>;
type Interval = ReturnType<typeof setInterval>;
type Immediate = ReturnType<typeof setImmediate>;
export { type Immediate, type Interval, type Timeout, canUseDOM, composeEventHandlers, getActiveElement, getOwnerDocument, getOwnerWindow, isFrame };

View file

@ -0,0 +1,76 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
canUseDOM: () => canUseDOM,
composeEventHandlers: () => composeEventHandlers,
getActiveElement: () => getActiveElement,
getOwnerDocument: () => getOwnerDocument,
getOwnerWindow: () => getOwnerWindow,
isFrame: () => isFrame
});
module.exports = __toCommonJS(index_exports);
// src/primitive.tsx
var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
return function handleEvent(event) {
originalEventHandler?.(event);
if (checkForDefaultPrevented === false || !event.defaultPrevented) {
return ourEventHandler?.(event);
}
};
}
function getOwnerWindow(element) {
if (!canUseDOM) {
throw new Error("Cannot access window outside of the DOM");
}
return element?.ownerDocument?.defaultView ?? window;
}
function getOwnerDocument(element) {
if (!canUseDOM) {
throw new Error("Cannot access document outside of the DOM");
}
return element?.ownerDocument ?? document;
}
function getActiveElement(node, activeDescendant = false) {
const { activeElement } = getOwnerDocument(node);
if (!activeElement?.nodeName) {
return null;
}
if (isFrame(activeElement) && activeElement.contentDocument) {
return getActiveElement(activeElement.contentDocument.body, activeDescendant);
}
if (activeDescendant) {
const id = activeElement.getAttribute("aria-activedescendant");
if (id) {
const element = getOwnerDocument(activeElement).getElementById(id);
if (element) {
return element;
}
}
}
return activeElement;
}
function isFrame(element) {
return element.tagName === "IFRAME";
}
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/index.ts", "../src/primitive.tsx"],
"sourcesContent": ["export * from './primitive';\nexport type * from './types';\n", "/* eslint-disable no-restricted-properties */\n\n/* eslint-disable no-restricted-globals */\nexport const canUseDOM = !!(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n/* eslint-enable no-restricted-globals */\n\nexport function composeEventHandlers<E extends { defaultPrevented: boolean }>(\n originalEventHandler?: (event: E) => void,\n ourEventHandler?: (event: E) => void,\n { checkForDefaultPrevented = true } = {}\n) {\n return function handleEvent(event: E) {\n originalEventHandler?.(event);\n\n if (checkForDefaultPrevented === false || !event.defaultPrevented) {\n return ourEventHandler?.(event);\n }\n };\n}\n\nexport function getOwnerWindow(element: Node | null | undefined) {\n if (!canUseDOM) {\n throw new Error('Cannot access window outside of the DOM');\n }\n // eslint-disable-next-line no-restricted-globals\n return element?.ownerDocument?.defaultView ?? window;\n}\n\nexport function getOwnerDocument(element: Node | null | undefined) {\n if (!canUseDOM) {\n throw new Error('Cannot access document outside of the DOM');\n }\n // eslint-disable-next-line no-restricted-globals\n return element?.ownerDocument ?? document;\n}\n\n/**\n * Lifted from https://github.com/ariakit/ariakit/blob/main/packages/ariakit-core/src/utils/dom.ts#L37\n * MIT License, Copyright (c) AriaKit.\n */\nexport function getActiveElement(\n node: Node | null | undefined,\n activeDescendant = false\n): HTMLElement | null {\n const { activeElement } = getOwnerDocument(node);\n if (!activeElement?.nodeName) {\n // `activeElement` might be an empty object if we're interacting with elements\n // inside of an iframe.\n return null;\n }\n\n if (isFrame(activeElement) && activeElement.contentDocument) {\n return getActiveElement(activeElement.contentDocument.body, activeDescendant);\n }\n\n if (activeDescendant) {\n const id = activeElement.getAttribute('aria-activedescendant');\n if (id) {\n const element = getOwnerDocument(activeElement).getElementById(id);\n if (element) {\n return element;\n }\n }\n }\n\n return activeElement as HTMLElement | null;\n}\n\nexport function isFrame(element: Element): element is HTMLIFrameElement {\n return element.tagName === 'IFRAME';\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,YAAY,CAAC,EACxB,OAAO,WAAW,eAClB,OAAO,YACP,OAAO,SAAS;AAIX,SAAS,qBACd,sBACA,iBACA,EAAE,2BAA2B,KAAK,IAAI,CAAC,GACvC;AACA,SAAO,SAAS,YAAY,OAAU;AACpC,2BAAuB,KAAK;AAE5B,QAAI,6BAA6B,SAAS,CAAC,MAAM,kBAAkB;AACjE,aAAO,kBAAkB,KAAK;AAAA,IAChC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,SAAkC;AAC/D,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AAEA,SAAO,SAAS,eAAe,eAAe;AAChD;AAEO,SAAS,iBAAiB,SAAkC;AACjE,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AAEA,SAAO,SAAS,iBAAiB;AACnC;AAMO,SAAS,iBACd,MACA,mBAAmB,OACC;AACpB,QAAM,EAAE,cAAc,IAAI,iBAAiB,IAAI;AAC/C,MAAI,CAAC,eAAe,UAAU;AAG5B,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,aAAa,KAAK,cAAc,iBAAiB;AAC3D,WAAO,iBAAiB,cAAc,gBAAgB,MAAM,gBAAgB;AAAA,EAC9E;AAEA,MAAI,kBAAkB;AACpB,UAAM,KAAK,cAAc,aAAa,uBAAuB;AAC7D,QAAI,IAAI;AACN,YAAM,UAAU,iBAAiB,aAAa,EAAE,eAAe,EAAE;AACjE,UAAI,SAAS;AACX,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,QAAQ,SAAgD;AACtE,SAAO,QAAQ,YAAY;AAC7B;",
"names": []
}

View file

@ -0,0 +1,53 @@
// src/primitive.tsx
var canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
return function handleEvent(event) {
originalEventHandler?.(event);
if (checkForDefaultPrevented === false || !event.defaultPrevented) {
return ourEventHandler?.(event);
}
};
}
function getOwnerWindow(element) {
if (!canUseDOM) {
throw new Error("Cannot access window outside of the DOM");
}
return element?.ownerDocument?.defaultView ?? window;
}
function getOwnerDocument(element) {
if (!canUseDOM) {
throw new Error("Cannot access document outside of the DOM");
}
return element?.ownerDocument ?? document;
}
function getActiveElement(node, activeDescendant = false) {
const { activeElement } = getOwnerDocument(node);
if (!activeElement?.nodeName) {
return null;
}
if (isFrame(activeElement) && activeElement.contentDocument) {
return getActiveElement(activeElement.contentDocument.body, activeDescendant);
}
if (activeDescendant) {
const id = activeElement.getAttribute("aria-activedescendant");
if (id) {
const element = getOwnerDocument(activeElement).getElementById(id);
if (element) {
return element;
}
}
}
return activeElement;
}
function isFrame(element) {
return element.tagName === "IFRAME";
}
export {
canUseDOM,
composeEventHandlers,
getActiveElement,
getOwnerDocument,
getOwnerWindow,
isFrame
};
//# sourceMappingURL=index.mjs.map

View file

@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/primitive.tsx"],
"sourcesContent": ["/* eslint-disable no-restricted-properties */\n\n/* eslint-disable no-restricted-globals */\nexport const canUseDOM = !!(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n/* eslint-enable no-restricted-globals */\n\nexport function composeEventHandlers<E extends { defaultPrevented: boolean }>(\n originalEventHandler?: (event: E) => void,\n ourEventHandler?: (event: E) => void,\n { checkForDefaultPrevented = true } = {}\n) {\n return function handleEvent(event: E) {\n originalEventHandler?.(event);\n\n if (checkForDefaultPrevented === false || !event.defaultPrevented) {\n return ourEventHandler?.(event);\n }\n };\n}\n\nexport function getOwnerWindow(element: Node | null | undefined) {\n if (!canUseDOM) {\n throw new Error('Cannot access window outside of the DOM');\n }\n // eslint-disable-next-line no-restricted-globals\n return element?.ownerDocument?.defaultView ?? window;\n}\n\nexport function getOwnerDocument(element: Node | null | undefined) {\n if (!canUseDOM) {\n throw new Error('Cannot access document outside of the DOM');\n }\n // eslint-disable-next-line no-restricted-globals\n return element?.ownerDocument ?? document;\n}\n\n/**\n * Lifted from https://github.com/ariakit/ariakit/blob/main/packages/ariakit-core/src/utils/dom.ts#L37\n * MIT License, Copyright (c) AriaKit.\n */\nexport function getActiveElement(\n node: Node | null | undefined,\n activeDescendant = false\n): HTMLElement | null {\n const { activeElement } = getOwnerDocument(node);\n if (!activeElement?.nodeName) {\n // `activeElement` might be an empty object if we're interacting with elements\n // inside of an iframe.\n return null;\n }\n\n if (isFrame(activeElement) && activeElement.contentDocument) {\n return getActiveElement(activeElement.contentDocument.body, activeDescendant);\n }\n\n if (activeDescendant) {\n const id = activeElement.getAttribute('aria-activedescendant');\n if (id) {\n const element = getOwnerDocument(activeElement).getElementById(id);\n if (element) {\n return element;\n }\n }\n }\n\n return activeElement as HTMLElement | null;\n}\n\nexport function isFrame(element: Element): element is HTMLIFrameElement {\n return element.tagName === 'IFRAME';\n}\n"],
"mappings": ";AAGO,IAAM,YAAY,CAAC,EACxB,OAAO,WAAW,eAClB,OAAO,YACP,OAAO,SAAS;AAIX,SAAS,qBACd,sBACA,iBACA,EAAE,2BAA2B,KAAK,IAAI,CAAC,GACvC;AACA,SAAO,SAAS,YAAY,OAAU;AACpC,2BAAuB,KAAK;AAE5B,QAAI,6BAA6B,SAAS,CAAC,MAAM,kBAAkB;AACjE,aAAO,kBAAkB,KAAK;AAAA,IAChC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,SAAkC;AAC/D,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AAEA,SAAO,SAAS,eAAe,eAAe;AAChD;AAEO,SAAS,iBAAiB,SAAkC;AACjE,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AAEA,SAAO,SAAS,iBAAiB;AACnC;AAMO,SAAS,iBACd,MACA,mBAAmB,OACC;AACpB,QAAM,EAAE,cAAc,IAAI,iBAAiB,IAAI;AAC/C,MAAI,CAAC,eAAe,UAAU;AAG5B,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,aAAa,KAAK,cAAc,iBAAiB;AAC3D,WAAO,iBAAiB,cAAc,gBAAgB,MAAM,gBAAgB;AAAA,EAC9E;AAEA,MAAI,kBAAkB;AACpB,UAAM,KAAK,cAAc,aAAa,uBAAuB;AAC7D,QAAI,IAAI;AACN,YAAM,UAAU,iBAAiB,aAAa,EAAE,eAAe,EAAE;AACjE,UAAI,SAAS;AACX,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,QAAQ,SAAgD;AACtE,SAAO,QAAQ,YAAY;AAC7B;",
"names": []
}

View file

@ -0,0 +1,47 @@
{
"name": "@radix-ui/primitive",
"version": "1.1.3",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"devDependencies": {
"eslint": "^9.18.0",
"typescript": "^5.7.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0",
"@repo/eslint-config": "0.0.0"
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,3 @@
# `react-collection`
This is an internal utility, not intended for public usage.

View file

@ -0,0 +1,98 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import React from 'react';
import { Slot } from '@radix-ui/react-slot';
type SlotProps$1 = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps$1 extends SlotProps$1 {
scope: any;
}
declare function createCollection$1<ItemElement extends HTMLElement, ItemData = {}>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps$1 & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, (scope: any) => () => ({
ref: React.RefObject<ItemElement | null>;
} & ItemData)[], _radix_ui_react_context.CreateScope];
declare class OrderedDict<K, V> extends Map<K, V> {
#private;
constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
set(key: K, value: V): this;
insert(index: number, key: K, value: V): this;
with(index: number, key: K, value: V): OrderedDict<K, V>;
before(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key: K, newKey: K, value: V): this;
after(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key: K, newKey: K, value: V): this;
first(): [K, V] | undefined;
last(): [K, V] | undefined;
clear(): void;
delete(key: K): boolean;
deleteAt(index: number): boolean;
at(index: number): V | undefined;
entryAt(index: number): [K, V] | undefined;
indexOf(key: K): number;
keyAt(index: number): K | undefined;
from(key: K, offset: number): V | undefined;
keyFrom(key: K, offset: number): K | undefined;
find(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): [K, V] | undefined;
findIndex(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): number;
filter<KK extends K, VV extends V>(predicate: (entry: [K, V], index: number, dict: OrderedDict<K, V>) => entry is [KK, VV], thisArg?: any): OrderedDict<KK, VV>;
filter(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): OrderedDict<K, V>;
map<U>(callbackfn: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => U, thisArg?: any): OrderedDict<K, U>;
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduce<U>(callbackfn: (previousValue: U, currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduceRight<U>(callbackfn: (previousValue: [K, V], currentValue: U, currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
toSorted(compareFn?: (a: [K, V], b: [K, V]) => number): OrderedDict<K, V>;
toReversed(): OrderedDict<K, V>;
toSpliced(start: number, deleteCount?: number): OrderedDict<K, V>;
toSpliced(start: number, deleteCount: number, ...items: [K, V][]): OrderedDict<K, V>;
slice(start?: number, end?: number): OrderedDict<K, V>;
every(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
some(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
}
type SlotProps = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps extends SlotProps {
scope: any;
}
interface BaseItemData {
id?: string;
}
type ItemDataWithElement<ItemData extends BaseItemData, ItemElement extends HTMLElement> = ItemData & {
element: ItemElement;
};
type ItemMap<ItemElement extends HTMLElement, ItemData extends BaseItemData> = OrderedDict<ItemElement, ItemDataWithElement<ItemData, ItemElement>>;
declare function createCollection<ItemElement extends HTMLElement, ItemData extends BaseItemData = BaseItemData>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
state?: [ItemMap: ItemMap<ItemElement, ItemData>, SetItemMap: React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, {
createCollectionScope: _radix_ui_react_context.CreateScope;
useCollection: (scope: any) => ItemMap<ItemElement, ItemData>;
useInitCollection: () => [ItemMap<ItemElement, ItemData>, React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}];
export { type CollectionProps$1 as CollectionProps, createCollection$1 as createCollection, type CollectionProps$1 as unstable_CollectionProps, createCollection as unstable_createCollection };

View file

@ -0,0 +1,98 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import React from 'react';
import { Slot } from '@radix-ui/react-slot';
type SlotProps$1 = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps$1 extends SlotProps$1 {
scope: any;
}
declare function createCollection$1<ItemElement extends HTMLElement, ItemData = {}>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps$1 & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, (scope: any) => () => ({
ref: React.RefObject<ItemElement | null>;
} & ItemData)[], _radix_ui_react_context.CreateScope];
declare class OrderedDict<K, V> extends Map<K, V> {
#private;
constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
set(key: K, value: V): this;
insert(index: number, key: K, value: V): this;
with(index: number, key: K, value: V): OrderedDict<K, V>;
before(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key: K, newKey: K, value: V): this;
after(key: K): [K, V] | undefined;
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key: K, newKey: K, value: V): this;
first(): [K, V] | undefined;
last(): [K, V] | undefined;
clear(): void;
delete(key: K): boolean;
deleteAt(index: number): boolean;
at(index: number): V | undefined;
entryAt(index: number): [K, V] | undefined;
indexOf(key: K): number;
keyAt(index: number): K | undefined;
from(key: K, offset: number): V | undefined;
keyFrom(key: K, offset: number): K | undefined;
find(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): [K, V] | undefined;
findIndex(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => boolean, thisArg?: any): number;
filter<KK extends K, VV extends V>(predicate: (entry: [K, V], index: number, dict: OrderedDict<K, V>) => entry is [KK, VV], thisArg?: any): OrderedDict<KK, VV>;
filter(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): OrderedDict<K, V>;
map<U>(callbackfn: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => U, thisArg?: any): OrderedDict<K, U>;
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduce(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduce<U>(callbackfn: (previousValue: U, currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V]): [K, V];
reduceRight(callbackfn: (previousValue: [K, V], currentEntry: [K, V], currentIndex: number, dictionary: OrderedDict<K, V>) => [K, V], initialValue: [K, V]): [K, V];
reduceRight<U>(callbackfn: (previousValue: [K, V], currentValue: U, currentIndex: number, dictionary: OrderedDict<K, V>) => U, initialValue: U): U;
toSorted(compareFn?: (a: [K, V], b: [K, V]) => number): OrderedDict<K, V>;
toReversed(): OrderedDict<K, V>;
toSpliced(start: number, deleteCount?: number): OrderedDict<K, V>;
toSpliced(start: number, deleteCount: number, ...items: [K, V][]): OrderedDict<K, V>;
slice(start?: number, end?: number): OrderedDict<K, V>;
every(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
some(predicate: (entry: [K, V], index: number, dictionary: OrderedDict<K, V>) => unknown, thisArg?: any): boolean;
}
type SlotProps = React.ComponentPropsWithoutRef<typeof Slot>;
interface CollectionProps extends SlotProps {
scope: any;
}
interface BaseItemData {
id?: string;
}
type ItemDataWithElement<ItemData extends BaseItemData, ItemElement extends HTMLElement> = ItemData & {
element: ItemElement;
};
type ItemMap<ItemElement extends HTMLElement, ItemData extends BaseItemData> = OrderedDict<ItemElement, ItemDataWithElement<ItemData, ItemElement>>;
declare function createCollection<ItemElement extends HTMLElement, ItemData extends BaseItemData = BaseItemData>(name: string): readonly [{
readonly Provider: React.FC<{
children?: React.ReactNode;
scope: any;
state?: [ItemMap: ItemMap<ItemElement, ItemData>, SetItemMap: React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}>;
readonly Slot: React.ForwardRefExoticComponent<CollectionProps & React.RefAttributes<HTMLElement>>;
readonly ItemSlot: React.ForwardRefExoticComponent<React.PropsWithoutRef<ItemData & {
children: React.ReactNode;
scope: any;
}> & React.RefAttributes<ItemElement>>;
}, {
createCollectionScope: _radix_ui_react_context.CreateScope;
useCollection: (scope: any) => ItemMap<ItemElement, ItemData>;
useInitCollection: () => [ItemMap<ItemElement, ItemData>, React.Dispatch<React.SetStateAction<ItemMap<ItemElement, ItemData>>>];
}];
export { type CollectionProps$1 as CollectionProps, createCollection$1 as createCollection, type CollectionProps$1 as unstable_CollectionProps, createCollection as unstable_createCollection };

View file

@ -0,0 +1,577 @@
"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);
// src/index.ts
var index_exports = {};
__export(index_exports, {
createCollection: () => createCollection,
unstable_createCollection: () => createCollection2
});
module.exports = __toCommonJS(index_exports);
// src/collection-legacy.tsx
var import_react = __toESM(require("react"));
var import_react_context = require("@radix-ui/react-context");
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
var import_react_slot = require("@radix-ui/react-slot");
var import_jsx_runtime = require("react/jsx-runtime");
function createCollection(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = (0, import_react_context.createContextScope)(PROVIDER_NAME);
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{ collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
);
const CollectionProvider = (props) => {
const { scope, children } = props;
const ref = import_react.default.useRef(null);
const itemMap = import_react.default.useRef(/* @__PURE__ */ new Map()).current;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
};
CollectionProvider.displayName = PROVIDER_NAME;
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = (0, import_react_slot.createSlot)(COLLECTION_SLOT_NAME);
const CollectionSlot = import_react.default.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.collectionRef);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = (0, import_react_slot.createSlot)(ITEM_SLOT_NAME);
const CollectionItemSlot = import_react.default.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = import_react.default.useRef(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
import_react.default.useEffect(() => {
context.itemMap.set(ref, { ref, ...itemData });
return () => void context.itemMap.delete(ref);
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useCollection(scope) {
const context = useCollectionContext(name + "CollectionConsumer", scope);
const getItems = import_react.default.useCallback(() => {
const collectionNode = context.collectionRef.current;
if (!collectionNode) return [];
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
const items = Array.from(context.itemMap.values());
const orderedItems = items.sort(
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
);
return orderedItems;
}, [context.collectionRef, context.itemMap]);
return getItems;
}
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
useCollection,
createCollectionScope
];
}
// src/collection.tsx
var import_react2 = __toESM(require("react"));
var import_react_context2 = require("@radix-ui/react-context");
var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
var import_react_slot2 = require("@radix-ui/react-slot");
// src/ordered-dictionary.ts
var __instanciated = /* @__PURE__ */ new WeakMap();
var OrderedDict = class _OrderedDict extends Map {
#keys;
constructor(entries) {
super(entries);
this.#keys = [...super.keys()];
__instanciated.set(this, true);
}
set(key, value) {
if (__instanciated.get(this)) {
if (this.has(key)) {
this.#keys[this.#keys.indexOf(key)] = key;
} else {
this.#keys.push(key);
}
}
super.set(key, value);
return this;
}
insert(index, key, value) {
const has = this.has(key);
const length = this.#keys.length;
const relativeIndex = toSafeInteger(index);
let actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
const safeIndex = actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
if (safeIndex === this.size || has && safeIndex === this.size - 1 || safeIndex === -1) {
this.set(key, value);
return this;
}
const size = this.size + (has ? 0 : 1);
if (relativeIndex < 0) {
actualIndex++;
}
const keys = [...this.#keys];
let nextValue;
let shouldSkip = false;
for (let i = actualIndex; i < size; i++) {
if (actualIndex === i) {
let nextKey = keys[i];
if (keys[i] === key) {
nextKey = keys[i + 1];
}
if (has) {
this.delete(key);
}
nextValue = this.get(nextKey);
this.set(key, value);
} else {
if (!shouldSkip && keys[i - 1] === key) {
shouldSkip = true;
}
const currentKey = keys[shouldSkip ? i : i - 1];
const currentValue = nextValue;
nextValue = this.get(currentKey);
this.delete(currentKey);
this.set(currentKey, currentValue);
}
}
return this;
}
with(index, key, value) {
const copy = new _OrderedDict(this);
copy.insert(index, key, value);
return copy;
}
before(key) {
const index = this.#keys.indexOf(key) - 1;
if (index < 0) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index, newKey, value);
}
after(key) {
let index = this.#keys.indexOf(key);
index = index === -1 || index === this.size - 1 ? -1 : index + 1;
if (index === -1) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index + 1, newKey, value);
}
first() {
return this.entryAt(0);
}
last() {
return this.entryAt(-1);
}
clear() {
this.#keys = [];
return super.clear();
}
delete(key) {
const deleted = super.delete(key);
if (deleted) {
this.#keys.splice(this.#keys.indexOf(key), 1);
}
return deleted;
}
deleteAt(index) {
const key = this.keyAt(index);
if (key !== void 0) {
return this.delete(key);
}
return false;
}
at(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return this.get(key);
}
}
entryAt(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return [key, this.get(key)];
}
}
indexOf(key) {
return this.#keys.indexOf(key);
}
keyAt(index) {
return at(this.#keys, index);
}
from(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.at(dest);
}
keyFrom(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.keyAt(dest);
}
find(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return entry;
}
index++;
}
return void 0;
}
findIndex(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return index;
}
index++;
}
return -1;
}
filter(predicate, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
entries.push(entry);
}
index++;
}
return new _OrderedDict(entries);
}
map(callbackfn, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
entries.push([entry[0], Reflect.apply(callbackfn, thisArg, [entry, index, this])]);
index++;
}
return new _OrderedDict(entries);
}
reduce(...args) {
const [callbackfn, initialValue] = args;
let index = 0;
let accumulator = initialValue ?? this.at(0);
for (const entry of this) {
if (index === 0 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
index++;
}
return accumulator;
}
reduceRight(...args) {
const [callbackfn, initialValue] = args;
let accumulator = initialValue ?? this.at(-1);
for (let index = this.size - 1; index >= 0; index--) {
const entry = this.at(index);
if (index === this.size - 1 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
}
return accumulator;
}
toSorted(compareFn) {
const entries = [...this.entries()].sort(compareFn);
return new _OrderedDict(entries);
}
toReversed() {
const reversed = new _OrderedDict();
for (let index = this.size - 1; index >= 0; index--) {
const key = this.keyAt(index);
const element = this.get(key);
reversed.set(key, element);
}
return reversed;
}
toSpliced(...args) {
const entries = [...this.entries()];
entries.splice(...args);
return new _OrderedDict(entries);
}
slice(start, end) {
const result = new _OrderedDict();
let stop = this.size - 1;
if (start === void 0) {
return result;
}
if (start < 0) {
start = start + this.size;
}
if (end !== void 0 && end > 0) {
stop = end - 1;
}
for (let index = start; index <= stop; index++) {
const key = this.keyAt(index);
const element = this.get(key);
result.set(key, element);
}
return result;
}
every(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (!Reflect.apply(predicate, thisArg, [entry, index, this])) {
return false;
}
index++;
}
return true;
}
some(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return true;
}
index++;
}
return false;
}
};
function at(array, index) {
if ("at" in Array.prototype) {
return Array.prototype.at.call(array, index);
}
const actualIndex = toSafeIndex(array, index);
return actualIndex === -1 ? void 0 : array[actualIndex];
}
function toSafeIndex(array, index) {
const length = array.length;
const relativeIndex = toSafeInteger(index);
const actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
return actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
}
function toSafeInteger(number) {
return number !== number || number === 0 ? 0 : Math.trunc(number);
}
// src/collection.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
function createCollection2(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = (0, import_react_context2.createContextScope)(PROVIDER_NAME);
const [CollectionContextProvider, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{
collectionElement: null,
collectionRef: { current: null },
collectionRefObject: { current: null },
itemMap: new OrderedDict(),
setItemMap: () => void 0
}
);
const CollectionProvider = ({ state, ...props }) => {
return state ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionProviderImpl, { ...props, state }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionInit, { ...props });
};
CollectionProvider.displayName = PROVIDER_NAME;
const CollectionInit = (props) => {
const state = useInitCollection();
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionProviderImpl, { ...props, state });
};
CollectionInit.displayName = PROVIDER_NAME + "Init";
const CollectionProviderImpl = (props) => {
const { scope, children, state } = props;
const ref = import_react2.default.useRef(null);
const [collectionElement, setCollectionElement] = import_react2.default.useState(
null
);
const composeRefs = (0, import_react_compose_refs2.useComposedRefs)(ref, setCollectionElement);
const [itemMap, setItemMap] = state;
import_react2.default.useEffect(() => {
if (!collectionElement) return;
const observer = getChildListObserver(() => {
});
observer.observe(collectionElement, {
childList: true,
subtree: true
});
return () => {
observer.disconnect();
};
}, [collectionElement]);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
CollectionContextProvider,
{
scope,
itemMap,
setItemMap,
collectionRef: composeRefs,
collectionRefObject: ref,
collectionElement,
children
}
);
};
CollectionProviderImpl.displayName = PROVIDER_NAME + "Impl";
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = (0, import_react_slot2.createSlot)(COLLECTION_SLOT_NAME);
const CollectionSlot = import_react2.default.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, context.collectionRef);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = (0, import_react_slot2.createSlot)(ITEM_SLOT_NAME);
const CollectionItemSlot = import_react2.default.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = import_react2.default.useRef(null);
const [element, setElement] = import_react2.default.useState(null);
const composedRefs = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, ref, setElement);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
const { setItemMap } = context;
const itemDataRef = import_react2.default.useRef(itemData);
if (!shallowEqual(itemDataRef.current, itemData)) {
itemDataRef.current = itemData;
}
const memoizedItemData = itemDataRef.current;
import_react2.default.useEffect(() => {
const itemData2 = memoizedItemData;
setItemMap((map) => {
if (!element) {
return map;
}
if (!map.has(element)) {
map.set(element, { ...itemData2, element });
return map.toSorted(sortByDocumentPosition);
}
return map.set(element, { ...itemData2, element }).toSorted(sortByDocumentPosition);
});
return () => {
setItemMap((map) => {
if (!element || !map.has(element)) {
return map;
}
map.delete(element);
return new OrderedDict(map);
});
};
}, [element, memoizedItemData, setItemMap]);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useInitCollection() {
return import_react2.default.useState(new OrderedDict());
}
function useCollection(scope) {
const { itemMap } = useCollectionContext(name + "CollectionConsumer", scope);
return itemMap;
}
const functions = {
createCollectionScope,
useCollection,
useInitCollection
};
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
functions
];
}
function shallowEqual(a, b) {
if (a === b) return true;
if (typeof a !== "object" || typeof b !== "object") return false;
if (a == null || b == null) return false;
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) return false;
for (const key of keysA) {
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
if (a[key] !== b[key]) return false;
}
return true;
}
function isElementPreceding(a, b) {
return !!(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);
}
function sortByDocumentPosition(a, b) {
return !a[1].element || !b[1].element ? 0 : isElementPreceding(a[1].element, b[1].element) ? -1 : 1;
}
function getChildListObserver(callback) {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
callback();
return;
}
}
});
return observer;
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,545 @@
"use client";
// src/collection-legacy.tsx
import React from "react";
import { createContextScope } from "@radix-ui/react-context";
import { useComposedRefs } from "@radix-ui/react-compose-refs";
import { createSlot } from "@radix-ui/react-slot";
import { jsx } from "react/jsx-runtime";
function createCollection(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = createContextScope(PROVIDER_NAME);
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{ collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
);
const CollectionProvider = (props) => {
const { scope, children } = props;
const ref = React.useRef(null);
const itemMap = React.useRef(/* @__PURE__ */ new Map()).current;
return /* @__PURE__ */ jsx(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
};
CollectionProvider.displayName = PROVIDER_NAME;
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = createSlot(COLLECTION_SLOT_NAME);
const CollectionSlot = React.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
return /* @__PURE__ */ jsx(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = createSlot(ITEM_SLOT_NAME);
const CollectionItemSlot = React.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = React.useRef(null);
const composedRefs = useComposedRefs(forwardedRef, ref);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
React.useEffect(() => {
context.itemMap.set(ref, { ref, ...itemData });
return () => void context.itemMap.delete(ref);
});
return /* @__PURE__ */ jsx(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useCollection(scope) {
const context = useCollectionContext(name + "CollectionConsumer", scope);
const getItems = React.useCallback(() => {
const collectionNode = context.collectionRef.current;
if (!collectionNode) return [];
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
const items = Array.from(context.itemMap.values());
const orderedItems = items.sort(
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
);
return orderedItems;
}, [context.collectionRef, context.itemMap]);
return getItems;
}
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
useCollection,
createCollectionScope
];
}
// src/collection.tsx
import React2 from "react";
import { createContextScope as createContextScope2 } from "@radix-ui/react-context";
import { useComposedRefs as useComposedRefs2 } from "@radix-ui/react-compose-refs";
import { createSlot as createSlot2 } from "@radix-ui/react-slot";
// src/ordered-dictionary.ts
var __instanciated = /* @__PURE__ */ new WeakMap();
var OrderedDict = class _OrderedDict extends Map {
#keys;
constructor(entries) {
super(entries);
this.#keys = [...super.keys()];
__instanciated.set(this, true);
}
set(key, value) {
if (__instanciated.get(this)) {
if (this.has(key)) {
this.#keys[this.#keys.indexOf(key)] = key;
} else {
this.#keys.push(key);
}
}
super.set(key, value);
return this;
}
insert(index, key, value) {
const has = this.has(key);
const length = this.#keys.length;
const relativeIndex = toSafeInteger(index);
let actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
const safeIndex = actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
if (safeIndex === this.size || has && safeIndex === this.size - 1 || safeIndex === -1) {
this.set(key, value);
return this;
}
const size = this.size + (has ? 0 : 1);
if (relativeIndex < 0) {
actualIndex++;
}
const keys = [...this.#keys];
let nextValue;
let shouldSkip = false;
for (let i = actualIndex; i < size; i++) {
if (actualIndex === i) {
let nextKey = keys[i];
if (keys[i] === key) {
nextKey = keys[i + 1];
}
if (has) {
this.delete(key);
}
nextValue = this.get(nextKey);
this.set(key, value);
} else {
if (!shouldSkip && keys[i - 1] === key) {
shouldSkip = true;
}
const currentKey = keys[shouldSkip ? i : i - 1];
const currentValue = nextValue;
nextValue = this.get(currentKey);
this.delete(currentKey);
this.set(currentKey, currentValue);
}
}
return this;
}
with(index, key, value) {
const copy = new _OrderedDict(this);
copy.insert(index, key, value);
return copy;
}
before(key) {
const index = this.#keys.indexOf(key) - 1;
if (index < 0) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position before the given key.
*/
setBefore(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index, newKey, value);
}
after(key) {
let index = this.#keys.indexOf(key);
index = index === -1 || index === this.size - 1 ? -1 : index + 1;
if (index === -1) {
return void 0;
}
return this.entryAt(index);
}
/**
* Sets a new key-value pair at the position after the given key.
*/
setAfter(key, newKey, value) {
const index = this.#keys.indexOf(key);
if (index === -1) {
return this;
}
return this.insert(index + 1, newKey, value);
}
first() {
return this.entryAt(0);
}
last() {
return this.entryAt(-1);
}
clear() {
this.#keys = [];
return super.clear();
}
delete(key) {
const deleted = super.delete(key);
if (deleted) {
this.#keys.splice(this.#keys.indexOf(key), 1);
}
return deleted;
}
deleteAt(index) {
const key = this.keyAt(index);
if (key !== void 0) {
return this.delete(key);
}
return false;
}
at(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return this.get(key);
}
}
entryAt(index) {
const key = at(this.#keys, index);
if (key !== void 0) {
return [key, this.get(key)];
}
}
indexOf(key) {
return this.#keys.indexOf(key);
}
keyAt(index) {
return at(this.#keys, index);
}
from(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.at(dest);
}
keyFrom(key, offset) {
const index = this.indexOf(key);
if (index === -1) {
return void 0;
}
let dest = index + offset;
if (dest < 0) dest = 0;
if (dest >= this.size) dest = this.size - 1;
return this.keyAt(dest);
}
find(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return entry;
}
index++;
}
return void 0;
}
findIndex(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return index;
}
index++;
}
return -1;
}
filter(predicate, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
entries.push(entry);
}
index++;
}
return new _OrderedDict(entries);
}
map(callbackfn, thisArg) {
const entries = [];
let index = 0;
for (const entry of this) {
entries.push([entry[0], Reflect.apply(callbackfn, thisArg, [entry, index, this])]);
index++;
}
return new _OrderedDict(entries);
}
reduce(...args) {
const [callbackfn, initialValue] = args;
let index = 0;
let accumulator = initialValue ?? this.at(0);
for (const entry of this) {
if (index === 0 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
index++;
}
return accumulator;
}
reduceRight(...args) {
const [callbackfn, initialValue] = args;
let accumulator = initialValue ?? this.at(-1);
for (let index = this.size - 1; index >= 0; index--) {
const entry = this.at(index);
if (index === this.size - 1 && args.length === 1) {
accumulator = entry;
} else {
accumulator = Reflect.apply(callbackfn, this, [accumulator, entry, index, this]);
}
}
return accumulator;
}
toSorted(compareFn) {
const entries = [...this.entries()].sort(compareFn);
return new _OrderedDict(entries);
}
toReversed() {
const reversed = new _OrderedDict();
for (let index = this.size - 1; index >= 0; index--) {
const key = this.keyAt(index);
const element = this.get(key);
reversed.set(key, element);
}
return reversed;
}
toSpliced(...args) {
const entries = [...this.entries()];
entries.splice(...args);
return new _OrderedDict(entries);
}
slice(start, end) {
const result = new _OrderedDict();
let stop = this.size - 1;
if (start === void 0) {
return result;
}
if (start < 0) {
start = start + this.size;
}
if (end !== void 0 && end > 0) {
stop = end - 1;
}
for (let index = start; index <= stop; index++) {
const key = this.keyAt(index);
const element = this.get(key);
result.set(key, element);
}
return result;
}
every(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (!Reflect.apply(predicate, thisArg, [entry, index, this])) {
return false;
}
index++;
}
return true;
}
some(predicate, thisArg) {
let index = 0;
for (const entry of this) {
if (Reflect.apply(predicate, thisArg, [entry, index, this])) {
return true;
}
index++;
}
return false;
}
};
function at(array, index) {
if ("at" in Array.prototype) {
return Array.prototype.at.call(array, index);
}
const actualIndex = toSafeIndex(array, index);
return actualIndex === -1 ? void 0 : array[actualIndex];
}
function toSafeIndex(array, index) {
const length = array.length;
const relativeIndex = toSafeInteger(index);
const actualIndex = relativeIndex >= 0 ? relativeIndex : length + relativeIndex;
return actualIndex < 0 || actualIndex >= length ? -1 : actualIndex;
}
function toSafeInteger(number) {
return number !== number || number === 0 ? 0 : Math.trunc(number);
}
// src/collection.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
function createCollection2(name) {
const PROVIDER_NAME = name + "CollectionProvider";
const [createCollectionContext, createCollectionScope] = createContextScope2(PROVIDER_NAME);
const [CollectionContextProvider, useCollectionContext] = createCollectionContext(
PROVIDER_NAME,
{
collectionElement: null,
collectionRef: { current: null },
collectionRefObject: { current: null },
itemMap: new OrderedDict(),
setItemMap: () => void 0
}
);
const CollectionProvider = ({ state, ...props }) => {
return state ? /* @__PURE__ */ jsx2(CollectionProviderImpl, { ...props, state }) : /* @__PURE__ */ jsx2(CollectionInit, { ...props });
};
CollectionProvider.displayName = PROVIDER_NAME;
const CollectionInit = (props) => {
const state = useInitCollection();
return /* @__PURE__ */ jsx2(CollectionProviderImpl, { ...props, state });
};
CollectionInit.displayName = PROVIDER_NAME + "Init";
const CollectionProviderImpl = (props) => {
const { scope, children, state } = props;
const ref = React2.useRef(null);
const [collectionElement, setCollectionElement] = React2.useState(
null
);
const composeRefs = useComposedRefs2(ref, setCollectionElement);
const [itemMap, setItemMap] = state;
React2.useEffect(() => {
if (!collectionElement) return;
const observer = getChildListObserver(() => {
});
observer.observe(collectionElement, {
childList: true,
subtree: true
});
return () => {
observer.disconnect();
};
}, [collectionElement]);
return /* @__PURE__ */ jsx2(
CollectionContextProvider,
{
scope,
itemMap,
setItemMap,
collectionRef: composeRefs,
collectionRefObject: ref,
collectionElement,
children
}
);
};
CollectionProviderImpl.displayName = PROVIDER_NAME + "Impl";
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
const CollectionSlotImpl = createSlot2(COLLECTION_SLOT_NAME);
const CollectionSlot = React2.forwardRef(
(props, forwardedRef) => {
const { scope, children } = props;
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
const composedRefs = useComposedRefs2(forwardedRef, context.collectionRef);
return /* @__PURE__ */ jsx2(CollectionSlotImpl, { ref: composedRefs, children });
}
);
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
const ITEM_DATA_ATTR = "data-radix-collection-item";
const CollectionItemSlotImpl = createSlot2(ITEM_SLOT_NAME);
const CollectionItemSlot = React2.forwardRef(
(props, forwardedRef) => {
const { scope, children, ...itemData } = props;
const ref = React2.useRef(null);
const [element, setElement] = React2.useState(null);
const composedRefs = useComposedRefs2(forwardedRef, ref, setElement);
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
const { setItemMap } = context;
const itemDataRef = React2.useRef(itemData);
if (!shallowEqual(itemDataRef.current, itemData)) {
itemDataRef.current = itemData;
}
const memoizedItemData = itemDataRef.current;
React2.useEffect(() => {
const itemData2 = memoizedItemData;
setItemMap((map) => {
if (!element) {
return map;
}
if (!map.has(element)) {
map.set(element, { ...itemData2, element });
return map.toSorted(sortByDocumentPosition);
}
return map.set(element, { ...itemData2, element }).toSorted(sortByDocumentPosition);
});
return () => {
setItemMap((map) => {
if (!element || !map.has(element)) {
return map;
}
map.delete(element);
return new OrderedDict(map);
});
};
}, [element, memoizedItemData, setItemMap]);
return /* @__PURE__ */ jsx2(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
}
);
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
function useInitCollection() {
return React2.useState(new OrderedDict());
}
function useCollection(scope) {
const { itemMap } = useCollectionContext(name + "CollectionConsumer", scope);
return itemMap;
}
const functions = {
createCollectionScope,
useCollection,
useInitCollection
};
return [
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
functions
];
}
function shallowEqual(a, b) {
if (a === b) return true;
if (typeof a !== "object" || typeof b !== "object") return false;
if (a == null || b == null) return false;
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) return false;
for (const key of keysA) {
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
if (a[key] !== b[key]) return false;
}
return true;
}
function isElementPreceding(a, b) {
return !!(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);
}
function sortByDocumentPosition(a, b) {
return !a[1].element || !b[1].element ? 0 : isElementPreceding(a[1].element, b[1].element) ? -1 : 1;
}
function getChildListObserver(callback) {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
callback();
return;
}
}
});
return observer;
}
export {
createCollection,
createCollection2 as unstable_createCollection
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,71 @@
{
"name": "@radix-ui/react-collection",
"version": "1.1.7",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-slot": "1.2.3"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0",
"@repo/eslint-config": "0.0.0"
},
"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
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,3 @@
# `react-presence`
This is an internal utility, not intended for public usage.

View file

@ -0,0 +1,12 @@
import * as React from 'react';
interface PresenceProps {
children: React.ReactElement | ((props: {
present: boolean;
}) => React.ReactElement);
present: boolean;
}
declare const Presence: React.FC<PresenceProps>;
declare const Root: React.FC<PresenceProps>;
export { Presence, type PresenceProps, Root };

View file

@ -0,0 +1,12 @@
import * as React from 'react';
interface PresenceProps {
children: React.ReactElement | ((props: {
present: boolean;
}) => React.ReactElement);
present: boolean;
}
declare const Presence: React.FC<PresenceProps>;
declare const Root: React.FC<PresenceProps>;
export { Presence, type PresenceProps, Root };

View file

@ -0,0 +1,171 @@
"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);
// src/index.ts
var index_exports = {};
__export(index_exports, {
Presence: () => Presence,
Root: () => Root
});
module.exports = __toCommonJS(index_exports);
// src/presence.tsx
var React2 = __toESM(require("react"));
var import_react_compose_refs = require("@radix-ui/react-compose-refs");
var import_react_use_layout_effect = require("@radix-ui/react-use-layout-effect");
// src/use-state-machine.tsx
var React = __toESM(require("react"));
function useStateMachine(initialState, machine) {
return React.useReducer((state, event) => {
const nextState = machine[state][event];
return nextState ?? state;
}, initialState);
}
// src/presence.tsx
var Presence = (props) => {
const { present, children } = props;
const presence = usePresence(present);
const child = typeof children === "function" ? children({ present: presence.isPresent }) : React2.Children.only(children);
const ref = (0, import_react_compose_refs.useComposedRefs)(presence.ref, getElementRef(child));
const forceMount = typeof children === "function";
return forceMount || presence.isPresent ? React2.cloneElement(child, { ref }) : null;
};
Presence.displayName = "Presence";
function usePresence(present) {
const [node, setNode] = React2.useState();
const stylesRef = React2.useRef(null);
const prevPresentRef = React2.useRef(present);
const prevAnimationNameRef = React2.useRef("none");
const initialState = present ? "mounted" : "unmounted";
const [state, send] = useStateMachine(initialState, {
mounted: {
UNMOUNT: "unmounted",
ANIMATION_OUT: "unmountSuspended"
},
unmountSuspended: {
MOUNT: "mounted",
ANIMATION_END: "unmounted"
},
unmounted: {
MOUNT: "mounted"
}
});
React2.useEffect(() => {
const currentAnimationName = getAnimationName(stylesRef.current);
prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
}, [state]);
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
const styles = stylesRef.current;
const wasPresent = prevPresentRef.current;
const hasPresentChanged = wasPresent !== present;
if (hasPresentChanged) {
const prevAnimationName = prevAnimationNameRef.current;
const currentAnimationName = getAnimationName(styles);
if (present) {
send("MOUNT");
} else if (currentAnimationName === "none" || styles?.display === "none") {
send("UNMOUNT");
} else {
const isAnimating = prevAnimationName !== currentAnimationName;
if (wasPresent && isAnimating) {
send("ANIMATION_OUT");
} else {
send("UNMOUNT");
}
}
prevPresentRef.current = present;
}
}, [present, send]);
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
if (node) {
let timeoutId;
const ownerWindow = node.ownerDocument.defaultView ?? window;
const handleAnimationEnd = (event) => {
const currentAnimationName = getAnimationName(stylesRef.current);
const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
if (event.target === node && isCurrentAnimation) {
send("ANIMATION_END");
if (!prevPresentRef.current) {
const currentFillMode = node.style.animationFillMode;
node.style.animationFillMode = "forwards";
timeoutId = ownerWindow.setTimeout(() => {
if (node.style.animationFillMode === "forwards") {
node.style.animationFillMode = currentFillMode;
}
});
}
}
};
const handleAnimationStart = (event) => {
if (event.target === node) {
prevAnimationNameRef.current = getAnimationName(stylesRef.current);
}
};
node.addEventListener("animationstart", handleAnimationStart);
node.addEventListener("animationcancel", handleAnimationEnd);
node.addEventListener("animationend", handleAnimationEnd);
return () => {
ownerWindow.clearTimeout(timeoutId);
node.removeEventListener("animationstart", handleAnimationStart);
node.removeEventListener("animationcancel", handleAnimationEnd);
node.removeEventListener("animationend", handleAnimationEnd);
};
} else {
send("ANIMATION_END");
}
}, [node, send]);
return {
isPresent: ["mounted", "unmountSuspended"].includes(state),
ref: React2.useCallback((node2) => {
stylesRef.current = node2 ? getComputedStyle(node2) : null;
setNode(node2);
}, [])
};
}
function getAnimationName(styles) {
return styles?.animationName || "none";
}
function getElementRef(element) {
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.ref;
}
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.props.ref;
}
return element.props.ref || element.ref;
}
var Root = Presence;
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,139 @@
"use client";
// src/presence.tsx
import * as React2 from "react";
import { useComposedRefs } from "@radix-ui/react-compose-refs";
import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
// src/use-state-machine.tsx
import * as React from "react";
function useStateMachine(initialState, machine) {
return React.useReducer((state, event) => {
const nextState = machine[state][event];
return nextState ?? state;
}, initialState);
}
// src/presence.tsx
var Presence = (props) => {
const { present, children } = props;
const presence = usePresence(present);
const child = typeof children === "function" ? children({ present: presence.isPresent }) : React2.Children.only(children);
const ref = useComposedRefs(presence.ref, getElementRef(child));
const forceMount = typeof children === "function";
return forceMount || presence.isPresent ? React2.cloneElement(child, { ref }) : null;
};
Presence.displayName = "Presence";
function usePresence(present) {
const [node, setNode] = React2.useState();
const stylesRef = React2.useRef(null);
const prevPresentRef = React2.useRef(present);
const prevAnimationNameRef = React2.useRef("none");
const initialState = present ? "mounted" : "unmounted";
const [state, send] = useStateMachine(initialState, {
mounted: {
UNMOUNT: "unmounted",
ANIMATION_OUT: "unmountSuspended"
},
unmountSuspended: {
MOUNT: "mounted",
ANIMATION_END: "unmounted"
},
unmounted: {
MOUNT: "mounted"
}
});
React2.useEffect(() => {
const currentAnimationName = getAnimationName(stylesRef.current);
prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
}, [state]);
useLayoutEffect(() => {
const styles = stylesRef.current;
const wasPresent = prevPresentRef.current;
const hasPresentChanged = wasPresent !== present;
if (hasPresentChanged) {
const prevAnimationName = prevAnimationNameRef.current;
const currentAnimationName = getAnimationName(styles);
if (present) {
send("MOUNT");
} else if (currentAnimationName === "none" || styles?.display === "none") {
send("UNMOUNT");
} else {
const isAnimating = prevAnimationName !== currentAnimationName;
if (wasPresent && isAnimating) {
send("ANIMATION_OUT");
} else {
send("UNMOUNT");
}
}
prevPresentRef.current = present;
}
}, [present, send]);
useLayoutEffect(() => {
if (node) {
let timeoutId;
const ownerWindow = node.ownerDocument.defaultView ?? window;
const handleAnimationEnd = (event) => {
const currentAnimationName = getAnimationName(stylesRef.current);
const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
if (event.target === node && isCurrentAnimation) {
send("ANIMATION_END");
if (!prevPresentRef.current) {
const currentFillMode = node.style.animationFillMode;
node.style.animationFillMode = "forwards";
timeoutId = ownerWindow.setTimeout(() => {
if (node.style.animationFillMode === "forwards") {
node.style.animationFillMode = currentFillMode;
}
});
}
}
};
const handleAnimationStart = (event) => {
if (event.target === node) {
prevAnimationNameRef.current = getAnimationName(stylesRef.current);
}
};
node.addEventListener("animationstart", handleAnimationStart);
node.addEventListener("animationcancel", handleAnimationEnd);
node.addEventListener("animationend", handleAnimationEnd);
return () => {
ownerWindow.clearTimeout(timeoutId);
node.removeEventListener("animationstart", handleAnimationStart);
node.removeEventListener("animationcancel", handleAnimationEnd);
node.removeEventListener("animationend", handleAnimationEnd);
};
} else {
send("ANIMATION_END");
}
}, [node, send]);
return {
isPresent: ["mounted", "unmountSuspended"].includes(state),
ref: React2.useCallback((node2) => {
stylesRef.current = node2 ? getComputedStyle(node2) : null;
setNode(node2);
}, [])
};
}
function getAnimationName(styles) {
return styles?.animationName || "none";
}
function getElementRef(element) {
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.ref;
}
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
if (mayWarn) {
return element.props.ref;
}
return element.props.ref || element.ref;
}
var Root = Presence;
export {
Presence,
Root
};
//# sourceMappingURL=index.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,69 @@
{
"name": "@radix-ui/react-presence",
"version": "1.1.5",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/typescript-config": "0.0.0",
"@repo/eslint-config": "0.0.0",
"@repo/builder": "0.0.0"
},
"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
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,3 @@
# `react-primitive`
This is an internal utility, not intended for public usage.

View file

@ -0,0 +1,52 @@
import * as React from 'react';
declare const NODES: readonly ["a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "select", "span", "svg", "ul"];
type Primitives = {
[E in (typeof NODES)[number]]: PrimitiveForwardRefComponent<E>;
};
type PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {
asChild?: boolean;
};
interface PrimitiveForwardRefComponent<E extends React.ElementType> extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {
}
declare const Primitive: Primitives;
/**
* Flush custom event dispatch
* https://github.com/radix-ui/primitives/pull/1378
*
* React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
*
* Internally, React prioritises events in the following order:
* - discrete
* - continuous
* - default
*
* https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
*
* `discrete` is an important distinction as updates within these events are applied immediately.
* React however, is not able to infer the priority of custom event types due to how they are detected internally.
* Because of this, it's possible for updates from custom events to be unexpectedly batched when
* dispatched by another `discrete` event.
*
* In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
* This utility should be used when dispatching a custom event from within another `discrete` event, this utility
* is not necessary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
* For example:
*
* dispatching a known click 👎
* target.dispatchEvent(new Event(click))
*
* dispatching a custom type within a non-discrete event 👎
* onScroll={(event) => event.target.dispatchEvent(new CustomEvent(customType))}
*
* dispatching a custom type within a `discrete` event 👍
* onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(customType))}
*
* Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
* this utility with them. This is because it's possible for those handlers to be called implicitly during render
* e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
*/
declare function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E): void;
declare const Root: Primitives;
export { Primitive, type PrimitivePropsWithRef, Root, dispatchDiscreteCustomEvent };

View file

@ -0,0 +1,52 @@
import * as React from 'react';
declare const NODES: readonly ["a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "select", "span", "svg", "ul"];
type Primitives = {
[E in (typeof NODES)[number]]: PrimitiveForwardRefComponent<E>;
};
type PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {
asChild?: boolean;
};
interface PrimitiveForwardRefComponent<E extends React.ElementType> extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {
}
declare const Primitive: Primitives;
/**
* Flush custom event dispatch
* https://github.com/radix-ui/primitives/pull/1378
*
* React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.
*
* Internally, React prioritises events in the following order:
* - discrete
* - continuous
* - default
*
* https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350
*
* `discrete` is an important distinction as updates within these events are applied immediately.
* React however, is not able to infer the priority of custom event types due to how they are detected internally.
* Because of this, it's possible for updates from custom events to be unexpectedly batched when
* dispatched by another `discrete` event.
*
* In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.
* This utility should be used when dispatching a custom event from within another `discrete` event, this utility
* is not necessary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.
* For example:
*
* dispatching a known click 👎
* target.dispatchEvent(new Event(click))
*
* dispatching a custom type within a non-discrete event 👎
* onScroll={(event) => event.target.dispatchEvent(new CustomEvent(customType))}
*
* dispatching a custom type within a `discrete` event 👍
* onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(customType))}
*
* Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use
* this utility with them. This is because it's possible for those handlers to be called implicitly during render
* e.g. when focus is within a component as it is unmounted, or when managing focus on mount.
*/
declare function dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E): void;
declare const Root: Primitives;
export { Primitive, type PrimitivePropsWithRef, Root, dispatchDiscreteCustomEvent };

View file

@ -0,0 +1,80 @@
"use strict";
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);
// src/index.ts
var index_exports = {};
__export(index_exports, {
Primitive: () => Primitive,
Root: () => Root,
dispatchDiscreteCustomEvent: () => dispatchDiscreteCustomEvent
});
module.exports = __toCommonJS(index_exports);
// src/primitive.tsx
var React = __toESM(require("react"));
var ReactDOM = __toESM(require("react-dom"));
var import_react_slot = require("@radix-ui/react-slot");
var import_jsx_runtime = require("react/jsx-runtime");
var NODES = [
"a",
"button",
"div",
"form",
"h2",
"h3",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"select",
"span",
"svg",
"ul"
];
var Primitive = NODES.reduce((primitive, node) => {
const Slot = (0, import_react_slot.createSlot)(`Primitive.${node}`);
const Node = React.forwardRef((props, forwardedRef) => {
const { asChild, ...primitiveProps } = props;
const Comp = asChild ? Slot : node;
if (typeof window !== "undefined") {
window[Symbol.for("radix-ui")] = true;
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Comp, { ...primitiveProps, ref: forwardedRef });
});
Node.displayName = `Primitive.${node}`;
return { ...primitive, [node]: Node };
}, {});
function dispatchDiscreteCustomEvent(target, event) {
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
}
var Root = Primitive;
//# sourceMappingURL=index.js.map

View file

@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/index.ts", "../src/primitive.tsx"],
"sourcesContent": ["export {\n Primitive,\n //\n Root,\n //\n dispatchDiscreteCustomEvent,\n} from './primitive';\nexport type { PrimitivePropsWithRef } from './primitive';\n", "import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { createSlot } from '@radix-ui/react-slot';\n\nconst NODES = [\n 'a',\n 'button',\n 'div',\n 'form',\n 'h2',\n 'h3',\n 'img',\n 'input',\n 'label',\n 'li',\n 'nav',\n 'ol',\n 'p',\n 'select',\n 'span',\n 'svg',\n 'ul',\n] as const;\n\ntype Primitives = { [E in (typeof NODES)[number]]: PrimitiveForwardRefComponent<E> };\ntype PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {\n asChild?: boolean;\n};\n\ninterface PrimitiveForwardRefComponent<E extends React.ElementType>\n extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {}\n\n/* -------------------------------------------------------------------------------------------------\n * Primitive\n * -----------------------------------------------------------------------------------------------*/\n\nconst Primitive = NODES.reduce((primitive, node) => {\n const Slot = createSlot(`Primitive.${node}`);\n const Node = React.forwardRef((props: PrimitivePropsWithRef<typeof node>, forwardedRef: any) => {\n const { asChild, ...primitiveProps } = props;\n const Comp: any = asChild ? Slot : node;\n\n if (typeof window !== 'undefined') {\n (window as any)[Symbol.for('radix-ui')] = true;\n }\n\n return <Comp {...primitiveProps} ref={forwardedRef} />;\n });\n\n Node.displayName = `Primitive.${node}`;\n\n return { ...primitive, [node]: Node };\n}, {} as Primitives);\n\n/* -------------------------------------------------------------------------------------------------\n * Utils\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * Flush custom event dispatch\n * https://github.com/radix-ui/primitives/pull/1378\n *\n * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.\n *\n * Internally, React prioritises events in the following order:\n * - discrete\n * - continuous\n * - default\n *\n * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350\n *\n * `discrete` is an important distinction as updates within these events are applied immediately.\n * React however, is not able to infer the priority of custom event types due to how they are detected internally.\n * Because of this, it's possible for updates from custom events to be unexpectedly batched when\n * dispatched by another `discrete` event.\n *\n * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.\n * This utility should be used when dispatching a custom event from within another `discrete` event, this utility\n * is not necessary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.\n * For example:\n *\n * dispatching a known click \uD83D\uDC4E\n * target.dispatchEvent(new Event(\u2018click\u2019))\n *\n * dispatching a custom type within a non-discrete event \uD83D\uDC4E\n * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(\u2018customType\u2019))}\n *\n * dispatching a custom type within a `discrete` event \uD83D\uDC4D\n * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(\u2018customType\u2019))}\n *\n * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use\n * this utility with them. This is because it's possible for those handlers to be called implicitly during render\n * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.\n */\n\nfunction dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E) {\n if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Primitive;\n\nexport {\n Primitive,\n //\n Root,\n //\n dispatchDiscreteCustomEvent,\n};\nexport type { PrimitivePropsWithRef };\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,eAA0B;AAC1B,wBAA2B;AA4ChB;AA1CX,IAAM,QAAQ;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,IAAM,YAAY,MAAM,OAAO,CAAC,WAAW,SAAS;AAClD,QAAM,WAAO,8BAAW,aAAa,IAAI,EAAE;AAC3C,QAAM,OAAa,iBAAW,CAAC,OAA2C,iBAAsB;AAC9F,UAAM,EAAE,SAAS,GAAG,eAAe,IAAI;AACvC,UAAM,OAAY,UAAU,OAAO;AAEnC,QAAI,OAAO,WAAW,aAAa;AACjC,MAAC,OAAe,OAAO,IAAI,UAAU,CAAC,IAAI;AAAA,IAC5C;AAEA,WAAO,4CAAC,QAAM,GAAG,gBAAgB,KAAK,cAAc;AAAA,EACtD,CAAC;AAED,OAAK,cAAc,aAAa,IAAI;AAEpC,SAAO,EAAE,GAAG,WAAW,CAAC,IAAI,GAAG,KAAK;AACtC,GAAG,CAAC,CAAe;AA2CnB,SAAS,4BAAmD,QAAqB,OAAU;AACzF,MAAI,OAAQ,CAAS,mBAAU,MAAM,OAAO,cAAc,KAAK,CAAC;AAClE;AAIA,IAAM,OAAO;",
"names": []
}

View file

@ -0,0 +1,47 @@
// src/primitive.tsx
import * as React from "react";
import * as ReactDOM from "react-dom";
import { createSlot } from "@radix-ui/react-slot";
import { jsx } from "react/jsx-runtime";
var NODES = [
"a",
"button",
"div",
"form",
"h2",
"h3",
"img",
"input",
"label",
"li",
"nav",
"ol",
"p",
"select",
"span",
"svg",
"ul"
];
var Primitive = NODES.reduce((primitive, node) => {
const Slot = createSlot(`Primitive.${node}`);
const Node = React.forwardRef((props, forwardedRef) => {
const { asChild, ...primitiveProps } = props;
const Comp = asChild ? Slot : node;
if (typeof window !== "undefined") {
window[Symbol.for("radix-ui")] = true;
}
return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
});
Node.displayName = `Primitive.${node}`;
return { ...primitive, [node]: Node };
}, {});
function dispatchDiscreteCustomEvent(target, event) {
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
}
var Root = Primitive;
export {
Primitive,
Root,
dispatchDiscreteCustomEvent
};
//# sourceMappingURL=index.mjs.map

View file

@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/primitive.tsx"],
"sourcesContent": ["import * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { createSlot } from '@radix-ui/react-slot';\n\nconst NODES = [\n 'a',\n 'button',\n 'div',\n 'form',\n 'h2',\n 'h3',\n 'img',\n 'input',\n 'label',\n 'li',\n 'nav',\n 'ol',\n 'p',\n 'select',\n 'span',\n 'svg',\n 'ul',\n] as const;\n\ntype Primitives = { [E in (typeof NODES)[number]]: PrimitiveForwardRefComponent<E> };\ntype PrimitivePropsWithRef<E extends React.ElementType> = React.ComponentPropsWithRef<E> & {\n asChild?: boolean;\n};\n\ninterface PrimitiveForwardRefComponent<E extends React.ElementType>\n extends React.ForwardRefExoticComponent<PrimitivePropsWithRef<E>> {}\n\n/* -------------------------------------------------------------------------------------------------\n * Primitive\n * -----------------------------------------------------------------------------------------------*/\n\nconst Primitive = NODES.reduce((primitive, node) => {\n const Slot = createSlot(`Primitive.${node}`);\n const Node = React.forwardRef((props: PrimitivePropsWithRef<typeof node>, forwardedRef: any) => {\n const { asChild, ...primitiveProps } = props;\n const Comp: any = asChild ? Slot : node;\n\n if (typeof window !== 'undefined') {\n (window as any)[Symbol.for('radix-ui')] = true;\n }\n\n return <Comp {...primitiveProps} ref={forwardedRef} />;\n });\n\n Node.displayName = `Primitive.${node}`;\n\n return { ...primitive, [node]: Node };\n}, {} as Primitives);\n\n/* -------------------------------------------------------------------------------------------------\n * Utils\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * Flush custom event dispatch\n * https://github.com/radix-ui/primitives/pull/1378\n *\n * React batches *all* event handlers since version 18, this introduces certain considerations when using custom event types.\n *\n * Internally, React prioritises events in the following order:\n * - discrete\n * - continuous\n * - default\n *\n * https://github.com/facebook/react/blob/a8a4742f1c54493df00da648a3f9d26e3db9c8b5/packages/react-dom/src/events/ReactDOMEventListener.js#L294-L350\n *\n * `discrete` is an important distinction as updates within these events are applied immediately.\n * React however, is not able to infer the priority of custom event types due to how they are detected internally.\n * Because of this, it's possible for updates from custom events to be unexpectedly batched when\n * dispatched by another `discrete` event.\n *\n * In order to ensure that updates from custom events are applied predictably, we need to manually flush the batch.\n * This utility should be used when dispatching a custom event from within another `discrete` event, this utility\n * is not necessary when dispatching known event types, or if dispatching a custom type inside a non-discrete event.\n * For example:\n *\n * dispatching a known click \uD83D\uDC4E\n * target.dispatchEvent(new Event(\u2018click\u2019))\n *\n * dispatching a custom type within a non-discrete event \uD83D\uDC4E\n * onScroll={(event) => event.target.dispatchEvent(new CustomEvent(\u2018customType\u2019))}\n *\n * dispatching a custom type within a `discrete` event \uD83D\uDC4D\n * onPointerDown={(event) => dispatchDiscreteCustomEvent(event.target, new CustomEvent(\u2018customType\u2019))}\n *\n * Note: though React classifies `focus`, `focusin` and `focusout` events as `discrete`, it's not recommended to use\n * this utility with them. This is because it's possible for those handlers to be called implicitly during render\n * e.g. when focus is within a component as it is unmounted, or when managing focus on mount.\n */\n\nfunction dispatchDiscreteCustomEvent<E extends CustomEvent>(target: E['target'], event: E) {\n if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Root = Primitive;\n\nexport {\n Primitive,\n //\n Root,\n //\n dispatchDiscreteCustomEvent,\n};\nexport type { PrimitivePropsWithRef };\n"],
"mappings": ";AAAA,YAAY,WAAW;AACvB,YAAY,cAAc;AAC1B,SAAS,kBAAkB;AA4ChB;AA1CX,IAAM,QAAQ;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAcA,IAAM,YAAY,MAAM,OAAO,CAAC,WAAW,SAAS;AAClD,QAAM,OAAO,WAAW,aAAa,IAAI,EAAE;AAC3C,QAAM,OAAa,iBAAW,CAAC,OAA2C,iBAAsB;AAC9F,UAAM,EAAE,SAAS,GAAG,eAAe,IAAI;AACvC,UAAM,OAAY,UAAU,OAAO;AAEnC,QAAI,OAAO,WAAW,aAAa;AACjC,MAAC,OAAe,OAAO,IAAI,UAAU,CAAC,IAAI;AAAA,IAC5C;AAEA,WAAO,oBAAC,QAAM,GAAG,gBAAgB,KAAK,cAAc;AAAA,EACtD,CAAC;AAED,OAAK,cAAc,aAAa,IAAI;AAEpC,SAAO,EAAE,GAAG,WAAW,CAAC,IAAI,GAAG,KAAK;AACtC,GAAG,CAAC,CAAe;AA2CnB,SAAS,4BAAmD,QAAqB,OAAU;AACzF,MAAI,OAAQ,CAAS,mBAAU,MAAM,OAAO,cAAc,KAAK,CAAC;AAClE;AAIA,IAAM,OAAO;",
"names": []
}

View file

@ -0,0 +1,68 @@
{
"name": "@radix-ui/react-primitive",
"version": "2.1.3",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/react-slot": "1.2.3"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0",
"@repo/eslint-config": "0.0.0"
},
"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
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}

79
node_modules/@radix-ui/react-toast/package.json generated vendored Normal file
View file

@ -0,0 +1,79 @@
{
"name": "@radix-ui/react-toast",
"version": "1.2.15",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-collection": "1.1.7",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-dismissable-layer": "1.1.11",
"@radix-ui/react-portal": "1.1.9",
"@radix-ui/react-presence": "1.1.5",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-use-callback-ref": "1.1.1",
"@radix-ui/react-use-controllable-state": "1.2.2",
"@radix-ui/react-visually-hidden": "1.2.3",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/builder": "0.0.0",
"@repo/eslint-config": "0.0.0",
"@repo/typescript-config": "0.0.0"
},
"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
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"clean": "rm -rf dist",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}