Files
NapCatQQ/.pnpm-store/v3/files/9e/dcd81eeacb85d84d1515e9affab3b1a3f1650db5cdb14447446eb699919afa4ac87f032db15733ffc542afc4646728ec01bd7908ae855727a47fc2a1046cef
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

50 lines
1.9 KiB
Plaintext

"use client";
// src/utils.ts
import { useContext, useMemo } from "react";
import { mergeProps, mergeRefs, useObjectRef } from "@react-aria/utils";
var DEFAULT_SLOT = Symbol("default");
function useSlottedContext(context, slot) {
let ctx = useContext(context);
if (slot === null) {
return null;
}
if (ctx && typeof ctx === "object" && "slots" in ctx && ctx.slots) {
let availableSlots = new Intl.ListFormat().format(Object.keys(ctx.slots).map((p) => `"${p}"`));
if (!slot && !ctx.slots[DEFAULT_SLOT]) {
throw new Error(`A slot prop is required. Valid slot names are ${availableSlots}.`);
}
let slotKey = slot || DEFAULT_SLOT;
if (!ctx.slots[slotKey]) {
throw new Error(`Invalid slot "${slot}". Valid slot names are ${availableSlots}.`);
}
return ctx.slots[slotKey];
}
return ctx;
}
function useContextProps(props, ref, context) {
let ctx = useSlottedContext(context, props.slot) || {};
let { ref: contextRef, ...contextProps } = ctx;
let mergedRef = useObjectRef(useMemo(() => mergeRefs(ref, contextRef), [ref, contextRef]));
let mergedProps = mergeProps(contextProps, props);
if ("style" in contextProps && contextProps.style && "style" in props && props.style) {
if (typeof contextProps.style === "function" || typeof props.style === "function") {
mergedProps.style = (renderProps) => {
let contextStyle = typeof contextProps.style === "function" ? contextProps.style(renderProps) : contextProps.style;
let defaultStyle = { ...renderProps.defaultStyle, ...contextStyle };
let style = typeof props.style === "function" ? props.style({ ...renderProps, defaultStyle }) : props.style;
return { ...defaultStyle, ...style };
};
} else {
mergedProps.style = { ...contextProps.style, ...props.style };
}
}
return [mergedProps, mergedRef];
}
export {
DEFAULT_SLOT,
useSlottedContext,
useContextProps
};