- ✅ Ticket 1.1: Estructura Clean Architecture en backend - ✅ Ticket 1.2: Schemas Zod compartidos - ✅ Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares) - ✅ Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares) - ✅ Ticket 1.5: Eliminación de duplicidades (~50 líneas) Cambios principales: - Creada estructura Clean Architecture en backend/src/ - Schemas Zod compartidos en backend/src/shared/schemas/ - Refactorización modular de drugs y procedures - Utilidades genéricas en src/utils/ (filter, validation) - Eliminados scripts obsoletos y documentación antigua - Corregidos errores: QueryClient, import test-error-handling - Build verificado y funcionando correctamente
722 lines
26 KiB
JavaScript
722 lines
26 KiB
JavaScript
import {
|
|
useCallbackRef
|
|
} from "./chunk-IFCS6WH6.js";
|
|
import {
|
|
require_react_dom
|
|
} from "./chunk-PBX5ABKV.js";
|
|
import {
|
|
composeRefs,
|
|
useComposedRefs
|
|
} from "./chunk-OHANU4DK.js";
|
|
import {
|
|
require_jsx_runtime
|
|
} from "./chunk-4UTF2CDO.js";
|
|
import {
|
|
require_react
|
|
} from "./chunk-BXEBRY3I.js";
|
|
import {
|
|
__toESM
|
|
} from "./chunk-V4OQ3NZ2.js";
|
|
|
|
// node_modules/@radix-ui/primitive/dist/index.mjs
|
|
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);
|
|
}
|
|
};
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-context/dist/index.mjs
|
|
var React = __toESM(require_react(), 1);
|
|
var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
let defaultContexts = [];
|
|
function createContext3(rootComponentName, defaultContext) {
|
|
const BaseContext = React.createContext(defaultContext);
|
|
const index = defaultContexts.length;
|
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
const Provider = (props) => {
|
|
const { scope, children, ...context } = props;
|
|
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
const value = React.useMemo(() => context, Object.values(context));
|
|
return (0, import_jsx_runtime.jsx)(Context.Provider, { value, children });
|
|
};
|
|
Provider.displayName = rootComponentName + "Provider";
|
|
function useContext22(consumerName, scope) {
|
|
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
const context = React.useContext(Context);
|
|
if (context) return context;
|
|
if (defaultContext !== void 0) return defaultContext;
|
|
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
}
|
|
return [Provider, useContext22];
|
|
}
|
|
const createScope = () => {
|
|
const scopeContexts = defaultContexts.map((defaultContext) => {
|
|
return React.createContext(defaultContext);
|
|
});
|
|
return function useScope(scope) {
|
|
const contexts = scope?.[scopeName] || scopeContexts;
|
|
return React.useMemo(
|
|
() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
|
|
[scope, contexts]
|
|
);
|
|
};
|
|
};
|
|
createScope.scopeName = scopeName;
|
|
return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
}
|
|
function composeContextScopes(...scopes) {
|
|
const baseScope = scopes[0];
|
|
if (scopes.length === 1) return baseScope;
|
|
const createScope = () => {
|
|
const scopeHooks = scopes.map((createScope2) => ({
|
|
useScope: createScope2(),
|
|
scopeName: createScope2.scopeName
|
|
}));
|
|
return function useComposedScopes(overrideScopes) {
|
|
const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
|
|
const scopeProps = useScope(overrideScopes);
|
|
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
return { ...nextScopes2, ...currentScope };
|
|
}, {});
|
|
return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
|
|
};
|
|
};
|
|
createScope.scopeName = baseScope.scopeName;
|
|
return createScope;
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-primitive/dist/index.mjs
|
|
var React3 = __toESM(require_react(), 1);
|
|
var ReactDOM = __toESM(require_react_dom(), 1);
|
|
|
|
// node_modules/@radix-ui/react-primitive/node_modules/@radix-ui/react-slot/dist/index.mjs
|
|
var React2 = __toESM(require_react(), 1);
|
|
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
|
function createSlot(ownerName) {
|
|
const SlotClone = createSlotClone(ownerName);
|
|
const Slot2 = React2.forwardRef((props, forwardedRef) => {
|
|
const { children, ...slotProps } = props;
|
|
const childrenArray = React2.Children.toArray(children);
|
|
const slottable = childrenArray.find(isSlottable);
|
|
if (slottable) {
|
|
const newElement = slottable.props.children;
|
|
const newChildren = childrenArray.map((child) => {
|
|
if (child === slottable) {
|
|
if (React2.Children.count(newElement) > 1) return React2.Children.only(null);
|
|
return React2.isValidElement(newElement) ? newElement.props.children : null;
|
|
} else {
|
|
return child;
|
|
}
|
|
});
|
|
return (0, import_jsx_runtime2.jsx)(SlotClone, { ...slotProps, ref: forwardedRef, children: React2.isValidElement(newElement) ? React2.cloneElement(newElement, void 0, newChildren) : null });
|
|
}
|
|
return (0, import_jsx_runtime2.jsx)(SlotClone, { ...slotProps, ref: forwardedRef, children });
|
|
});
|
|
Slot2.displayName = `${ownerName}.Slot`;
|
|
return Slot2;
|
|
}
|
|
var Slot = createSlot("Slot");
|
|
function createSlotClone(ownerName) {
|
|
const SlotClone = React2.forwardRef((props, forwardedRef) => {
|
|
const { children, ...slotProps } = props;
|
|
if (React2.isValidElement(children)) {
|
|
const childrenRef = getElementRef(children);
|
|
const props2 = mergeProps(slotProps, children.props);
|
|
if (children.type !== React2.Fragment) {
|
|
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
|
|
}
|
|
return React2.cloneElement(children, props2);
|
|
}
|
|
return React2.Children.count(children) > 1 ? React2.Children.only(null) : null;
|
|
});
|
|
SlotClone.displayName = `${ownerName}.SlotClone`;
|
|
return SlotClone;
|
|
}
|
|
var SLOTTABLE_IDENTIFIER = /* @__PURE__ */ Symbol("radix.slottable");
|
|
function createSlottable(ownerName) {
|
|
const Slottable2 = ({ children }) => {
|
|
return (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
|
|
};
|
|
Slottable2.displayName = `${ownerName}.Slottable`;
|
|
Slottable2.__radixId = SLOTTABLE_IDENTIFIER;
|
|
return Slottable2;
|
|
}
|
|
var Slottable = createSlottable("Slottable");
|
|
function isSlottable(child) {
|
|
return React2.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
|
|
}
|
|
function mergeProps(slotProps, childProps) {
|
|
const overrideProps = { ...childProps };
|
|
for (const propName in childProps) {
|
|
const slotPropValue = slotProps[propName];
|
|
const childPropValue = childProps[propName];
|
|
const isHandler = /^on[A-Z]/.test(propName);
|
|
if (isHandler) {
|
|
if (slotPropValue && childPropValue) {
|
|
overrideProps[propName] = (...args) => {
|
|
const result = childPropValue(...args);
|
|
slotPropValue(...args);
|
|
return result;
|
|
};
|
|
} else if (slotPropValue) {
|
|
overrideProps[propName] = slotPropValue;
|
|
}
|
|
} else if (propName === "style") {
|
|
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
} else if (propName === "className") {
|
|
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
}
|
|
}
|
|
return { ...slotProps, ...overrideProps };
|
|
}
|
|
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;
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-primitive/dist/index.mjs
|
|
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
|
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 Slot2 = createSlot(`Primitive.${node}`);
|
|
const Node = React3.forwardRef((props, forwardedRef) => {
|
|
const { asChild, ...primitiveProps } = props;
|
|
const Comp = asChild ? Slot2 : node;
|
|
if (typeof window !== "undefined") {
|
|
window[/* @__PURE__ */ Symbol.for("radix-ui")] = true;
|
|
}
|
|
return (0, import_jsx_runtime3.jsx)(Comp, { ...primitiveProps, ref: forwardedRef });
|
|
});
|
|
Node.displayName = `Primitive.${node}`;
|
|
return { ...primitive, [node]: Node };
|
|
}, {});
|
|
function dispatchDiscreteCustomEvent(target, event) {
|
|
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-dismissable-layer/dist/index.mjs
|
|
var React5 = __toESM(require_react(), 1);
|
|
|
|
// node_modules/@radix-ui/react-use-escape-keydown/dist/index.mjs
|
|
var React4 = __toESM(require_react(), 1);
|
|
function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
|
|
const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
|
|
React4.useEffect(() => {
|
|
const handleKeyDown = (event) => {
|
|
if (event.key === "Escape") {
|
|
onEscapeKeyDown(event);
|
|
}
|
|
};
|
|
ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
}, [onEscapeKeyDown, ownerDocument]);
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-dismissable-layer/dist/index.mjs
|
|
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
var DISMISSABLE_LAYER_NAME = "DismissableLayer";
|
|
var CONTEXT_UPDATE = "dismissableLayer.update";
|
|
var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
|
|
var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
|
|
var originalBodyPointerEvents;
|
|
var DismissableLayerContext = React5.createContext({
|
|
layers: /* @__PURE__ */ new Set(),
|
|
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
|
|
branches: /* @__PURE__ */ new Set()
|
|
});
|
|
var DismissableLayer = React5.forwardRef(
|
|
(props, forwardedRef) => {
|
|
const {
|
|
disableOutsidePointerEvents = false,
|
|
onEscapeKeyDown,
|
|
onPointerDownOutside,
|
|
onFocusOutside,
|
|
onInteractOutside,
|
|
onDismiss,
|
|
...layerProps
|
|
} = props;
|
|
const context = React5.useContext(DismissableLayerContext);
|
|
const [node, setNode] = React5.useState(null);
|
|
const ownerDocument = node?.ownerDocument ?? globalThis?.document;
|
|
const [, force] = React5.useState({});
|
|
const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
|
|
const layers = Array.from(context.layers);
|
|
const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
|
|
const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
|
|
const index = node ? layers.indexOf(node) : -1;
|
|
const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
|
|
const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
|
|
const pointerDownOutside = usePointerDownOutside((event) => {
|
|
const target = event.target;
|
|
const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
|
|
onPointerDownOutside?.(event);
|
|
onInteractOutside?.(event);
|
|
if (!event.defaultPrevented) onDismiss?.();
|
|
}, ownerDocument);
|
|
const focusOutside = useFocusOutside((event) => {
|
|
const target = event.target;
|
|
const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
if (isFocusInBranch) return;
|
|
onFocusOutside?.(event);
|
|
onInteractOutside?.(event);
|
|
if (!event.defaultPrevented) onDismiss?.();
|
|
}, ownerDocument);
|
|
useEscapeKeydown((event) => {
|
|
const isHighestLayer = index === context.layers.size - 1;
|
|
if (!isHighestLayer) return;
|
|
onEscapeKeyDown?.(event);
|
|
if (!event.defaultPrevented && onDismiss) {
|
|
event.preventDefault();
|
|
onDismiss();
|
|
}
|
|
}, ownerDocument);
|
|
React5.useEffect(() => {
|
|
if (!node) return;
|
|
if (disableOutsidePointerEvents) {
|
|
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
|
|
ownerDocument.body.style.pointerEvents = "none";
|
|
}
|
|
context.layersWithOutsidePointerEventsDisabled.add(node);
|
|
}
|
|
context.layers.add(node);
|
|
dispatchUpdate();
|
|
return () => {
|
|
if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
|
|
ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
|
|
}
|
|
};
|
|
}, [node, ownerDocument, disableOutsidePointerEvents, context]);
|
|
React5.useEffect(() => {
|
|
return () => {
|
|
if (!node) return;
|
|
context.layers.delete(node);
|
|
context.layersWithOutsidePointerEventsDisabled.delete(node);
|
|
dispatchUpdate();
|
|
};
|
|
}, [node, context]);
|
|
React5.useEffect(() => {
|
|
const handleUpdate = () => force({});
|
|
document.addEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
}, []);
|
|
return (0, import_jsx_runtime4.jsx)(
|
|
Primitive.div,
|
|
{
|
|
...layerProps,
|
|
ref: composedRefs,
|
|
style: {
|
|
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
...props.style
|
|
},
|
|
onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
onPointerDownCapture: composeEventHandlers(
|
|
props.onPointerDownCapture,
|
|
pointerDownOutside.onPointerDownCapture
|
|
)
|
|
}
|
|
);
|
|
}
|
|
);
|
|
DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
|
|
var BRANCH_NAME = "DismissableLayerBranch";
|
|
var DismissableLayerBranch = React5.forwardRef((props, forwardedRef) => {
|
|
const context = React5.useContext(DismissableLayerContext);
|
|
const ref = React5.useRef(null);
|
|
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
React5.useEffect(() => {
|
|
const node = ref.current;
|
|
if (node) {
|
|
context.branches.add(node);
|
|
return () => {
|
|
context.branches.delete(node);
|
|
};
|
|
}
|
|
}, [context.branches]);
|
|
return (0, import_jsx_runtime4.jsx)(Primitive.div, { ...props, ref: composedRefs });
|
|
});
|
|
DismissableLayerBranch.displayName = BRANCH_NAME;
|
|
function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
|
|
const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
|
|
const isPointerInsideReactTreeRef = React5.useRef(false);
|
|
const handleClickRef = React5.useRef(() => {
|
|
});
|
|
React5.useEffect(() => {
|
|
const handlePointerDown = (event) => {
|
|
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
let handleAndDispatchPointerDownOutsideEvent2 = function() {
|
|
handleAndDispatchCustomEvent(
|
|
POINTER_DOWN_OUTSIDE,
|
|
handlePointerDownOutside,
|
|
eventDetail,
|
|
{ discrete: true }
|
|
);
|
|
};
|
|
var handleAndDispatchPointerDownOutsideEvent = handleAndDispatchPointerDownOutsideEvent2;
|
|
const eventDetail = { originalEvent: event };
|
|
if (event.pointerType === "touch") {
|
|
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
|
|
ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
|
|
} else {
|
|
handleAndDispatchPointerDownOutsideEvent2();
|
|
}
|
|
} else {
|
|
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
}
|
|
isPointerInsideReactTreeRef.current = false;
|
|
};
|
|
const timerId = window.setTimeout(() => {
|
|
ownerDocument.addEventListener("pointerdown", handlePointerDown);
|
|
}, 0);
|
|
return () => {
|
|
window.clearTimeout(timerId);
|
|
ownerDocument.removeEventListener("pointerdown", handlePointerDown);
|
|
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
};
|
|
}, [ownerDocument, handlePointerDownOutside]);
|
|
return {
|
|
// ensures we check React component tree (not just DOM tree)
|
|
onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
|
|
};
|
|
}
|
|
function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
|
|
const handleFocusOutside = useCallbackRef(onFocusOutside);
|
|
const isFocusInsideReactTreeRef = React5.useRef(false);
|
|
React5.useEffect(() => {
|
|
const handleFocus = (event) => {
|
|
if (event.target && !isFocusInsideReactTreeRef.current) {
|
|
const eventDetail = { originalEvent: event };
|
|
handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
discrete: false
|
|
});
|
|
}
|
|
};
|
|
ownerDocument.addEventListener("focusin", handleFocus);
|
|
return () => ownerDocument.removeEventListener("focusin", handleFocus);
|
|
}, [ownerDocument, handleFocusOutside]);
|
|
return {
|
|
onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
|
|
onBlurCapture: () => isFocusInsideReactTreeRef.current = false
|
|
};
|
|
}
|
|
function dispatchUpdate() {
|
|
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
document.dispatchEvent(event);
|
|
}
|
|
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
const target = detail.originalEvent.target;
|
|
const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
|
|
if (handler) target.addEventListener(name, handler, { once: true });
|
|
if (discrete) {
|
|
dispatchDiscreteCustomEvent(target, event);
|
|
} else {
|
|
target.dispatchEvent(event);
|
|
}
|
|
}
|
|
var Root = DismissableLayer;
|
|
var Branch = DismissableLayerBranch;
|
|
|
|
// node_modules/@radix-ui/react-use-layout-effect/dist/index.mjs
|
|
var React6 = __toESM(require_react(), 1);
|
|
var useLayoutEffect2 = globalThis?.document ? React6.useLayoutEffect : () => {
|
|
};
|
|
|
|
// node_modules/@radix-ui/react-portal/dist/index.mjs
|
|
var React7 = __toESM(require_react(), 1);
|
|
var import_react_dom = __toESM(require_react_dom(), 1);
|
|
var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
|
|
var PORTAL_NAME = "Portal";
|
|
var Portal = React7.forwardRef((props, forwardedRef) => {
|
|
const { container: containerProp, ...portalProps } = props;
|
|
const [mounted, setMounted] = React7.useState(false);
|
|
useLayoutEffect2(() => setMounted(true), []);
|
|
const container = containerProp || mounted && globalThis?.document?.body;
|
|
return container ? import_react_dom.default.createPortal((0, import_jsx_runtime5.jsx)(Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
|
|
});
|
|
Portal.displayName = PORTAL_NAME;
|
|
|
|
// node_modules/@radix-ui/react-presence/dist/index.mjs
|
|
var React22 = __toESM(require_react(), 1);
|
|
var React8 = __toESM(require_react(), 1);
|
|
function useStateMachine(initialState, machine) {
|
|
return React8.useReducer((state, event) => {
|
|
const nextState = machine[state][event];
|
|
return nextState ?? state;
|
|
}, initialState);
|
|
}
|
|
var Presence = (props) => {
|
|
const { present, children } = props;
|
|
const presence = usePresence(present);
|
|
const child = typeof children === "function" ? children({ present: presence.isPresent }) : React22.Children.only(children);
|
|
const ref = useComposedRefs(presence.ref, getElementRef2(child));
|
|
const forceMount = typeof children === "function";
|
|
return forceMount || presence.isPresent ? React22.cloneElement(child, { ref }) : null;
|
|
};
|
|
Presence.displayName = "Presence";
|
|
function usePresence(present) {
|
|
const [node, setNode] = React22.useState();
|
|
const stylesRef = React22.useRef(null);
|
|
const prevPresentRef = React22.useRef(present);
|
|
const prevAnimationNameRef = React22.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"
|
|
}
|
|
});
|
|
React22.useEffect(() => {
|
|
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
|
|
}, [state]);
|
|
useLayoutEffect2(() => {
|
|
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]);
|
|
useLayoutEffect2(() => {
|
|
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: React22.useCallback((node2) => {
|
|
stylesRef.current = node2 ? getComputedStyle(node2) : null;
|
|
setNode(node2);
|
|
}, [])
|
|
};
|
|
}
|
|
function getAnimationName(styles) {
|
|
return styles?.animationName || "none";
|
|
}
|
|
function getElementRef2(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;
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-use-controllable-state/dist/index.mjs
|
|
var React10 = __toESM(require_react(), 1);
|
|
var React23 = __toESM(require_react(), 1);
|
|
|
|
// node_modules/@radix-ui/react-use-effect-event/dist/index.mjs
|
|
var React9 = __toESM(require_react(), 1);
|
|
var useReactEffectEvent = React9[" useEffectEvent ".trim().toString()];
|
|
var useReactInsertionEffect = React9[" useInsertionEffect ".trim().toString()];
|
|
|
|
// node_modules/@radix-ui/react-use-controllable-state/dist/index.mjs
|
|
var useInsertionEffect = React10[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
|
|
function useControllableState({
|
|
prop,
|
|
defaultProp,
|
|
onChange = () => {
|
|
},
|
|
caller
|
|
}) {
|
|
const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
|
|
defaultProp,
|
|
onChange
|
|
});
|
|
const isControlled = prop !== void 0;
|
|
const value = isControlled ? prop : uncontrolledProp;
|
|
if (true) {
|
|
const isControlledRef = React10.useRef(prop !== void 0);
|
|
React10.useEffect(() => {
|
|
const wasControlled = isControlledRef.current;
|
|
if (wasControlled !== isControlled) {
|
|
const from = wasControlled ? "controlled" : "uncontrolled";
|
|
const to = isControlled ? "controlled" : "uncontrolled";
|
|
console.warn(
|
|
`${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
|
|
);
|
|
}
|
|
isControlledRef.current = isControlled;
|
|
}, [isControlled, caller]);
|
|
}
|
|
const setValue = React10.useCallback(
|
|
(nextValue) => {
|
|
if (isControlled) {
|
|
const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
|
|
if (value2 !== prop) {
|
|
onChangeRef.current?.(value2);
|
|
}
|
|
} else {
|
|
setUncontrolledProp(nextValue);
|
|
}
|
|
},
|
|
[isControlled, prop, setUncontrolledProp, onChangeRef]
|
|
);
|
|
return [value, setValue];
|
|
}
|
|
function useUncontrolledState({
|
|
defaultProp,
|
|
onChange
|
|
}) {
|
|
const [value, setValue] = React10.useState(defaultProp);
|
|
const prevValueRef = React10.useRef(value);
|
|
const onChangeRef = React10.useRef(onChange);
|
|
useInsertionEffect(() => {
|
|
onChangeRef.current = onChange;
|
|
}, [onChange]);
|
|
React10.useEffect(() => {
|
|
if (prevValueRef.current !== value) {
|
|
onChangeRef.current?.(value);
|
|
prevValueRef.current = value;
|
|
}
|
|
}, [value, prevValueRef]);
|
|
return [value, setValue, onChangeRef];
|
|
}
|
|
function isFunction(value) {
|
|
return typeof value === "function";
|
|
}
|
|
|
|
// node_modules/@radix-ui/react-visually-hidden/dist/index.mjs
|
|
var React11 = __toESM(require_react(), 1);
|
|
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
|
|
var VISUALLY_HIDDEN_STYLES = Object.freeze({
|
|
// See: https://github.com/twbs/bootstrap/blob/main/scss/mixins/_visually-hidden.scss
|
|
position: "absolute",
|
|
border: 0,
|
|
width: 1,
|
|
height: 1,
|
|
padding: 0,
|
|
margin: -1,
|
|
overflow: "hidden",
|
|
clip: "rect(0, 0, 0, 0)",
|
|
whiteSpace: "nowrap",
|
|
wordWrap: "normal"
|
|
});
|
|
var NAME = "VisuallyHidden";
|
|
var VisuallyHidden = React11.forwardRef(
|
|
(props, forwardedRef) => {
|
|
return (0, import_jsx_runtime6.jsx)(
|
|
Primitive.span,
|
|
{
|
|
...props,
|
|
ref: forwardedRef,
|
|
style: { ...VISUALLY_HIDDEN_STYLES, ...props.style }
|
|
}
|
|
);
|
|
}
|
|
);
|
|
VisuallyHidden.displayName = NAME;
|
|
var Root2 = VisuallyHidden;
|
|
|
|
export {
|
|
composeEventHandlers,
|
|
createContextScope,
|
|
Primitive,
|
|
dispatchDiscreteCustomEvent,
|
|
DismissableLayer,
|
|
Root,
|
|
Branch,
|
|
useLayoutEffect2,
|
|
Portal,
|
|
Presence,
|
|
useControllableState,
|
|
VisuallyHidden,
|
|
Root2
|
|
};
|
|
//# sourceMappingURL=chunk-QHJT3T76.js.map
|