Download node_modules/@radix-ui/react-context/dist/index.mjs from metarm/QMetaRam: direct link, hf CLI and curl.
- Browser
- Download file 4.3 kB
-
https://huggingface.co/metarm/QMetaRam/resolve/main/node_modules/%40radix-ui/react-context/dist/index.mjs
- Command line
-
hf download hf://metarm/QMetaRam/node_modules/@radix-ui/react-context/dist/index.mjs
-
curl -L -o index.mjs https://huggingface.co/metarm/QMetaRam/resolve/main/node_modules/%40radix-ui/react-context/dist/index.mjs
4.3 kB
| var __defProp = Object.defineProperty; | |
| var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | |
| // src/create-context.tsx | |
| import * as React from "react"; | |
| import { jsx } from "react/jsx-runtime"; | |
| // @__NO_SIDE_EFFECTS__ | |
| function createContext2(rootComponentName, defaultContext) { | |
| const Context = React.createContext(defaultContext); | |
| Context.displayName = rootComponentName + "Context"; | |
| const Provider = /* @__PURE__ */ __name((props) => { | |
| const { children, ...context } = props; | |
| const value = React.useMemo(() => context, Object.values(context)); | |
| return /* @__PURE__ */ jsx(Context.Provider, { value, children }); | |
| }, "Provider"); | |
| Provider.displayName = rootComponentName + "Provider"; | |
| function useContext2(consumerName, options = {}) { | |
| const { optional = false } = options; | |
| const context = React.useContext(Context); | |
| if (context) return context; | |
| if (defaultContext !== void 0) return defaultContext; | |
| if (optional) return void 0; | |
| throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``); | |
| } | |
| __name(useContext2, "useContext"); | |
| return [Provider, useContext2]; | |
| } | |
| __name(createContext2, "createContext"); | |
| // @__NO_SIDE_EFFECTS__ | |
| function createContextScope(scopeName, createContextScopeDeps = []) { | |
| let defaultContexts = []; | |
| function createContext3(rootComponentName, defaultContext) { | |
| const BaseContext = React.createContext(defaultContext); | |
| BaseContext.displayName = rootComponentName + "Context"; | |
| const index = defaultContexts.length; | |
| defaultContexts = [...defaultContexts, defaultContext]; | |
| const Provider = /* @__PURE__ */ __name((props) => { | |
| const { scope, children, ...context } = props; | |
| const Context = scope?.[scopeName]?.[index] || BaseContext; | |
| const value = React.useMemo(() => context, Object.values(context)); | |
| return /* @__PURE__ */ jsx(Context.Provider, { value, children }); | |
| }, "Provider"); | |
| Provider.displayName = rootComponentName + "Provider"; | |
| function useContext2(consumerName, scope, options = {}) { | |
| const { optional = false } = options; | |
| const Context = scope?.[scopeName]?.[index] || BaseContext; | |
| const context = React.useContext(Context); | |
| if (context) return context; | |
| if (defaultContext !== void 0) return defaultContext; | |
| if (optional) return void 0; | |
| throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``); | |
| } | |
| __name(useContext2, "useContext"); | |
| return [Provider, useContext2]; | |
| } | |
| __name(createContext3, "createContext"); | |
| const createScope = /* @__PURE__ */ __name(() => { | |
| const scopeContexts = defaultContexts.map((defaultContext) => { | |
| return React.createContext(defaultContext); | |
| }); | |
| return /* @__PURE__ */ __name(function useScope(scope) { | |
| const contexts = scope?.[scopeName] || scopeContexts; | |
| return React.useMemo( | |
| () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }), | |
| [scope, contexts] | |
| ); | |
| }, "useScope"); | |
| }, "createScope"); | |
| createScope.scopeName = scopeName; | |
| return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)]; | |
| } | |
| __name(createContextScope, "createContextScope"); | |
| function composeContextScopes(...scopes) { | |
| const baseScope = scopes[0]; | |
| if (scopes.length === 1) return baseScope; | |
| const createScope = /* @__PURE__ */ __name(() => { | |
| const scopeHooks = scopes.map((createScope2) => ({ | |
| useScope: createScope2(), | |
| scopeName: createScope2.scopeName | |
| })); | |
| return /* @__PURE__ */ __name(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]); | |
| }, "useComposedScopes"); | |
| }, "createScope"); | |
| createScope.scopeName = baseScope.scopeName; | |
| return createScope; | |
| } | |
| __name(composeContextScopes, "composeContextScopes"); | |
| export { | |
| createContext2 as createContext, | |
| createContextScope | |
| }; | |
| //# sourceMappingURL=index.mjs.map | |