Download node_modules/@radix-ui/react-context/dist/index.js from metarm/QMetaRam: direct link, hf CLI and curl.
- Browser
- Download file 5.86 kB
-
https://huggingface.co/metarm/QMetaRam/resolve/main/node_modules/%40radix-ui/react-context/dist/index.js
- Command line
-
hf download hf://metarm/QMetaRam/node_modules/@radix-ui/react-context/dist/index.js
-
curl -L -o index.js https://huggingface.co/metarm/QMetaRam/resolve/main/node_modules/%40radix-ui/react-context/dist/index.js
5.86 kB
| ; | |
| 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 __name = (target, value) => __defProp(target, "name", { value, configurable: true }); | |
| 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, { | |
| createContext: () => createContext2, | |
| createContextScope: () => createContextScope | |
| }); | |
| module.exports = __toCommonJS(index_exports); | |
| // src/create-context.tsx | |
| var React = __toESM(require("react")); | |
| var import_jsx_runtime = require("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__ */ (0, import_jsx_runtime.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__ */ (0, import_jsx_runtime.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"); | |
| //# sourceMappingURL=index.js.map | |