🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@radix-ui/react-context

Package Overview
Dependencies
Maintainers
4
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-context - npm Package Compare versions

Comparing version
1.1.4
to
1.2.0-rc.1782930601752
+29
-4
dist/index.d.mts
import * as React from 'react';
declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType): readonly [React.FC<ContextValueType & {
type ContextProvider<ContextValueType extends object | null> = React.FC<ContextValueType & {
children: React.ReactNode;
}>, (consumerName: string) => ContextValueType];
}>;
interface UseAssertedContext<ContextValueType extends object | null> {
(consumerName: string): ContextValueType;
}
interface UseContext<ContextValueType extends object | null> {
(consumerName: string): ContextValueType;
(consumerName: string, options: {
optional: true;
}): ContextValueType | undefined;
}
declare function createContext<ContextValueType extends object | null>(rootComponentName: string): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>];
declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext: ContextValueType): readonly [ContextProvider<ContextValueType>, UseAssertedContext<ContextValueType>];
type Scope<C = any> = {

@@ -16,7 +27,21 @@ [scopeName: string]: React.Context<C>[];

}
declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType) => readonly [React.FC<ContextValueType & {
type ScopedContextProvider<ContextValueType extends object | null> = React.FC<ContextValueType & {
scope: Scope<ContextValueType>;
children: React.ReactNode;
}>, (consumerName: string, scope: Scope<ContextValueType | undefined>) => ContextValueType], CreateScope];
}>;
interface UseScopedContext<ContextValueType extends object | null> {
(consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;
(consumerName: string, scope: Scope<ContextValueType | undefined>, options: {
optional?: true;
}): ContextValueType | undefined;
}
interface UseAssertedScopedContext<ContextValueType extends object | null> {
(consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;
}
interface CreateScopedContext {
<ContextValueType extends object | null>(rootComponentName: string): readonly [ScopedContextProvider<ContextValueType>, UseScopedContext<ContextValueType>];
<ContextValueType extends object | null>(rootComponentName: string, defaultContext: ContextValueType): readonly [ScopedContextProvider<ContextValueType>, UseAssertedScopedContext<ContextValueType>];
}
declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [CreateScopedContext, CreateScope];
export { type CreateScope, type Scope, createContext, createContextScope };
import * as React from 'react';
declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType): readonly [React.FC<ContextValueType & {
type ContextProvider<ContextValueType extends object | null> = React.FC<ContextValueType & {
children: React.ReactNode;
}>, (consumerName: string) => ContextValueType];
}>;
interface UseAssertedContext<ContextValueType extends object | null> {
(consumerName: string): ContextValueType;
}
interface UseContext<ContextValueType extends object | null> {
(consumerName: string): ContextValueType;
(consumerName: string, options: {
optional: true;
}): ContextValueType | undefined;
}
declare function createContext<ContextValueType extends object | null>(rootComponentName: string): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>];
declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext: ContextValueType): readonly [ContextProvider<ContextValueType>, UseAssertedContext<ContextValueType>];
type Scope<C = any> = {

@@ -16,7 +27,21 @@ [scopeName: string]: React.Context<C>[];

}
declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType) => readonly [React.FC<ContextValueType & {
type ScopedContextProvider<ContextValueType extends object | null> = React.FC<ContextValueType & {
scope: Scope<ContextValueType>;
children: React.ReactNode;
}>, (consumerName: string, scope: Scope<ContextValueType | undefined>) => ContextValueType], CreateScope];
}>;
interface UseScopedContext<ContextValueType extends object | null> {
(consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;
(consumerName: string, scope: Scope<ContextValueType | undefined>, options: {
optional?: true;
}): ContextValueType | undefined;
}
interface UseAssertedScopedContext<ContextValueType extends object | null> {
(consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;
}
interface CreateScopedContext {
<ContextValueType extends object | null>(rootComponentName: string): readonly [ScopedContextProvider<ContextValueType>, UseScopedContext<ContextValueType>];
<ContextValueType extends object | null>(rootComponentName: string, defaultContext: ContextValueType): readonly [ScopedContextProvider<ContextValueType>, UseAssertedScopedContext<ContextValueType>];
}
declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [CreateScopedContext, CreateScope];
export { type CreateScope, type Scope, createContext, createContextScope };
+6
-2

@@ -50,6 +50,8 @@ "use strict";

Provider.displayName = rootComponentName + "Provider";
function useContext2(consumerName) {
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}\``);

@@ -73,3 +75,4 @@ }

Provider.displayName = rootComponentName + "Provider";
function useContext2(consumerName, scope) {
function useContext2(consumerName, scope, options = {}) {
const { optional = false } = options;
const Context = scope?.[scopeName]?.[index] || BaseContext;

@@ -79,2 +82,3 @@ const context = React.useContext(Context);

if (defaultContext !== void 0) return defaultContext;
if (optional) return void 0;
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);

@@ -81,0 +85,0 @@ }

{
"version": 3,
"sources": ["../src/index.ts", "../src/create-context.tsx"],
"sourcesContent": ["export { createContext, createContextScope } from './create-context';\nexport type { CreateScope, Scope } from './create-context';\n", "import * as React from 'react';\n\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n) {\n const Context = React.createContext<ContextValueType | undefined>(defaultContext);\n Context.displayName = rootComponentName + 'Context';\n\n const Provider: React.FC<ContextValueType & { children: React.ReactNode }> = (props) => {\n const { children, ...context } = props;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(consumerName: string) {\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext] as const;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * createContextScope\n * -----------------------------------------------------------------------------------------------*/\n\ntype Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined;\ntype ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope };\ninterface CreateScope {\n scopeName: string;\n (): ScopeHook;\n}\n\nfunction createContextScope(scopeName: string, createContextScopeDeps: CreateScope[] = []) {\n let defaultContexts: any[] = [];\n\n /* -----------------------------------------------------------------------------------------------\n * createContext\n * ---------------------------------------------------------------------------------------------*/\n\n function createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n ) {\n const BaseContext = React.createContext<ContextValueType | undefined>(defaultContext);\n BaseContext.displayName = rootComponentName + 'Context';\n const index = defaultContexts.length;\n defaultContexts = [...defaultContexts, defaultContext];\n\n const Provider: React.FC<\n ContextValueType & { scope: Scope<ContextValueType>; children: React.ReactNode }\n > = (props) => {\n const { scope, children, ...context } = props;\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(consumerName: string, scope: Scope<ContextValueType | undefined>) {\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext] as const;\n }\n\n /* -----------------------------------------------------------------------------------------------\n * createScope\n * ---------------------------------------------------------------------------------------------*/\n\n const createScope: CreateScope = () => {\n const scopeContexts = defaultContexts.map((defaultContext) => {\n return React.createContext(defaultContext);\n });\n return function useScope(scope: Scope) {\n const contexts = scope?.[scopeName] || scopeContexts;\n return React.useMemo(\n () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),\n [scope, contexts],\n );\n };\n };\n\n createScope.scopeName = scopeName;\n return [createContext, composeContextScopes(createScope, ...createContextScopeDeps)] as const;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * composeContextScopes\n * -----------------------------------------------------------------------------------------------*/\n\nfunction composeContextScopes(...scopes: [CreateScope, ...CreateScope[]]): CreateScope {\n const baseScope = scopes[0];\n if (scopes.length === 1) return baseScope;\n\n const createScope: CreateScope = () => {\n const scopeHooks = scopes.map((createScope) => ({\n useScope: createScope(),\n scopeName: createScope.scopeName,\n }));\n\n return function useComposedScopes(overrideScopes) {\n const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {\n // We are calling a hook inside a callback which React warns against to avoid inconsistent\n // renders, however, scoping doesn't have render side effects so we ignore the rule.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const scopeProps = useScope(overrideScopes);\n const currentScope = scopeProps[`__scope${scopeName}`];\n return { ...nextScopes, ...currentScope };\n }, {});\n\n return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);\n };\n };\n\n createScope.scopeName = baseScope.scopeName;\n return createScope;\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nexport { createContext, createContextScope };\nexport type { CreateScope, Scope };\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,YAAuB;AAcZ;AAZX,SAASC,eACP,mBACA,gBACA;AACA,QAAM,UAAgB,oBAA4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B,IAAI;AAAA,IACpF;AAEA,WAAO,CAAC,UAAUA,WAAU;AAAA,EAC9B;AAMA,QAAM,cAA2B,MAAM;AACrC,UAAM,gBAAgB,gBAAgB,IAAI,CAAC,mBAAmB;AAC5D,aAAa,oBAAc,cAAc;AAAA,IAC3C,CAAC;AACD,WAAO,SAAS,SAAS,OAAc;AACrC,YAAM,WAAW,QAAQ,SAAS,KAAK;AACvC,aAAa;AAAA,QACX,OAAO,EAAE,CAAC,UAAU,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,EAAE;AAAA,QACtE,CAAC,OAAO,QAAQ;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAEA,cAAY,YAAY;AACxB,SAAO,CAACD,gBAAe,qBAAqB,aAAa,GAAG,sBAAsB,CAAC;AACrF;AAMA,SAAS,wBAAwB,QAAsD;AACrF,QAAM,YAAY,OAAO,CAAC;AAC1B,MAAI,OAAO,WAAW,EAAG,QAAO;AAEhC,QAAM,cAA2B,MAAM;AACrC,UAAM,aAAa,OAAO,IAAI,CAACE,kBAAiB;AAAA,MAC9C,UAAUA,aAAY;AAAA,MACtB,WAAWA,aAAY;AAAA,IACzB,EAAE;AAEF,WAAO,SAAS,kBAAkB,gBAAgB;AAChD,YAAM,aAAa,WAAW,OAAO,CAACC,aAAY,EAAE,UAAU,UAAU,MAAM;AAI5E,cAAM,aAAa,SAAS,cAAc;AAC1C,cAAM,eAAe,WAAW,UAAU,SAAS,EAAE;AACrD,eAAO,EAAE,GAAGA,aAAY,GAAG,aAAa;AAAA,MAC1C,GAAG,CAAC,CAAC;AAEL,aAAa,cAAQ,OAAO,EAAE,CAAC,UAAU,UAAU,SAAS,EAAE,GAAG,WAAW,IAAI,CAAC,UAAU,CAAC;AAAA,IAC9F;AAAA,EACF;AAEA,cAAY,YAAY,UAAU;AAClC,SAAO;AACT;",
"sourcesContent": ["export { createContext, createContextScope } from './create-context';\nexport type { CreateScope, Scope } from './create-context';\n", "import * as React from 'react';\n\ntype ContextProvider<ContextValueType extends object | null> = React.FC<\n ContextValueType & {\n children: React.ReactNode;\n }\n>;\n\ninterface UseAssertedContext<ContextValueType extends object | null> {\n (consumerName: string): ContextValueType;\n}\n\ninterface UseContext<ContextValueType extends object | null> {\n (consumerName: string): ContextValueType;\n (consumerName: string, options: { optional: true }): ContextValueType | undefined;\n}\n\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>];\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext: ContextValueType,\n): readonly [ContextProvider<ContextValueType>, UseAssertedContext<ContextValueType>];\n\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>] {\n const Context = React.createContext<ContextValueType | undefined>(defaultContext);\n Context.displayName = rootComponentName + 'Context';\n\n const Provider: ContextProvider<ContextValueType> = (props) => {\n const { children, ...context } = props;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(consumerName: string): ContextValueType;\n function useContext(\n consumerName: string,\n options: { optional: true },\n ): ContextValueType | undefined;\n\n function useContext(\n consumerName: string,\n options: { optional?: boolean } = {},\n ): ContextValueType | undefined {\n const { optional = false } = options;\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n if (optional) return undefined;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext];\n}\n\n/* -------------------------------------------------------------------------------------------------\n * createContextScope\n * -----------------------------------------------------------------------------------------------*/\n\ntype Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined;\ntype ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope };\ninterface CreateScope {\n scopeName: string;\n (): ScopeHook;\n}\n\ntype ScopedContextProvider<ContextValueType extends object | null> = React.FC<\n ContextValueType & {\n scope: Scope<ContextValueType>;\n children: React.ReactNode;\n }\n>;\n\ninterface UseScopedContext<ContextValueType extends object | null> {\n (consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;\n (\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options: { optional?: true },\n ): ContextValueType | undefined;\n}\n\ninterface UseAssertedScopedContext<ContextValueType extends object | null> {\n (consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;\n}\n\ninterface CreateScopedContext {\n <ContextValueType extends object | null>(\n rootComponentName: string,\n ): readonly [ScopedContextProvider<ContextValueType>, UseScopedContext<ContextValueType>];\n <ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext: ContextValueType,\n ): readonly [ScopedContextProvider<ContextValueType>, UseAssertedScopedContext<ContextValueType>];\n}\n\nfunction createContextScope(\n scopeName: string,\n createContextScopeDeps: CreateScope[] = [],\n): readonly [CreateScopedContext, CreateScope] {\n let defaultContexts: any[] = [];\n\n /* -----------------------------------------------------------------------------------------------\n * createContext\n * ---------------------------------------------------------------------------------------------*/\n\n function createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n ) {\n const BaseContext = React.createContext<ContextValueType | undefined>(defaultContext);\n BaseContext.displayName = rootComponentName + 'Context';\n const index = defaultContexts.length;\n defaultContexts = [...defaultContexts, defaultContext];\n\n const Provider: ScopedContextProvider<ContextValueType> = (props) => {\n const { scope, children, ...context } = props;\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n ): ContextValueType;\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options: { optional: true },\n ): ContextValueType | undefined;\n\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options: { optional?: boolean } = {},\n ): ContextValueType | undefined {\n const { optional = false } = options;\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n if (optional) return undefined;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext] as const;\n }\n\n /* -----------------------------------------------------------------------------------------------\n * createScope\n * ---------------------------------------------------------------------------------------------*/\n\n const createScope: CreateScope = () => {\n const scopeContexts = defaultContexts.map((defaultContext) => {\n return React.createContext(defaultContext);\n });\n return function useScope(scope: Scope) {\n const contexts = scope?.[scopeName] || scopeContexts;\n return React.useMemo(\n () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),\n [scope, contexts],\n );\n };\n };\n\n createScope.scopeName = scopeName;\n return [createContext, composeContextScopes(createScope, ...createContextScopeDeps)] as const;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * composeContextScopes\n * -----------------------------------------------------------------------------------------------*/\n\nfunction composeContextScopes(...scopes: [CreateScope, ...CreateScope[]]): CreateScope {\n const baseScope = scopes[0];\n if (scopes.length === 1) return baseScope;\n\n const createScope: CreateScope = () => {\n const scopeHooks = scopes.map((createScope) => ({\n useScope: createScope(),\n scopeName: createScope.scopeName,\n }));\n\n return function useComposedScopes(overrideScopes) {\n const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {\n // We are calling a hook inside a callback which React warns against to avoid inconsistent\n // renders, however, scoping doesn't have render side effects so we ignore the rule.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const scopeProps = useScope(overrideScopes);\n const currentScope = scopeProps[`__scope${scopeName}`];\n return { ...nextScopes, ...currentScope };\n }, {});\n\n return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);\n };\n };\n\n createScope.scopeName = baseScope.scopeName;\n return createScope;\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nexport { createContext, createContextScope };\nexport type {\n CreateScope,\n CreateScopedContext,\n Scope,\n UseAssertedContext,\n UseAssertedScopedContext,\n UseContext,\n UseScopedContext,\n};\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,YAAuB;AAqCZ;AAZX,SAASC,eACP,mBACA,gBAC4E;AAC5E,QAAM,UAAgB,oBAA4C,cAAc;AAChF,UAAQ,cAAc,oBAAoB;AAE1C,QAAM,WAA8C,CAAC,UAAU;AAC7D,UAAM,EAAE,UAAU,GAAG,QAAQ,IAAI;AAGjC,UAAM,QAAc,cAAQ,MAAM,SAAS,OAAO,OAAO,OAAO,CAAC;AACjE,WAAO,4CAAC,QAAQ,UAAR,EAAiB,OAAe,UAAS;AAAA,EACnD;AAEA,WAAS,cAAc,oBAAoB;AAQ3C,WAASC,YACP,cACA,UAAkC,CAAC,GACL;AAC9B,UAAM,EAAE,WAAW,MAAM,IAAI;AAC7B,UAAM,UAAgB,iBAAW,OAAO;AACxC,QAAI,QAAS,QAAO;AACpB,QAAI,mBAAmB,OAAW,QAAO;AACzC,QAAI,SAAU,QAAO;AAErB,UAAM,IAAI,MAAM,KAAK,YAAY,4BAA4B,iBAAiB,IAAI;AAAA,EACpF;AAEA,SAAO,CAAC,UAAUA,WAAU;AAC9B;AA2CA,SAAS,mBACP,WACA,yBAAwC,CAAC,GACI;AAC7C,MAAI,kBAAyB,CAAC;AAM9B,WAASD,eACP,mBACA,gBACA;AACA,UAAM,cAAoB,oBAA4C,cAAc;AACpF,gBAAY,cAAc,oBAAoB;AAC9C,UAAM,QAAQ,gBAAgB;AAC9B,sBAAkB,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A2B,MAAM;AACrC,UAAM,aAAa,OAAO,IAAI,CAACE,kBAAiB;AAAA,MAC9C,UAAUA,aAAY;AAAA,MACtB,WAAWA,aAAY;AAAA,IACzB,EAAE;AAEF,WAAO,SAAS,kBAAkB,gBAAgB;AAChD,YAAM,aAAa,WAAW,OAAO,CAACC,aAAY,EAAE,UAAU,UAAU,MAAM;AAI5E,cAAM,aAAa,SAAS,cAAc;AAC1C,cAAM,eAAe,WAAW,UAAU,SAAS,EAAE;AACrD,eAAO,EAAE,GAAGA,aAAY,GAAG,aAAa;AAAA,MAC1C,GAAG,CAAC,CAAC;AAEL,aAAa,cAAQ,OAAO,EAAE,CAAC,UAAU,UAAU,SAAS,EAAE,GAAG,WAAW,IAAI,CAAC,UAAU,CAAC;AAAA,IAC9F;AAAA,EACF;AAEA,cAAY,YAAY,UAAU;AAClC,SAAO;AACT;",
"names": ["createContext", "createContext", "useContext", "createScope", "nextScopes"]
}

@@ -13,6 +13,8 @@ // src/create-context.tsx

Provider.displayName = rootComponentName + "Provider";
function useContext2(consumerName) {
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}\``);

@@ -36,3 +38,4 @@ }

Provider.displayName = rootComponentName + "Provider";
function useContext2(consumerName, scope) {
function useContext2(consumerName, scope, options = {}) {
const { optional = false } = options;
const Context = scope?.[scopeName]?.[index] || BaseContext;

@@ -42,2 +45,3 @@ const context = React.useContext(Context);

if (defaultContext !== void 0) return defaultContext;
if (optional) return void 0;
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);

@@ -44,0 +48,0 @@ }

{
"version": 3,
"sources": ["../src/create-context.tsx"],
"sourcesContent": ["import * as React from 'react';\n\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n) {\n const Context = React.createContext<ContextValueType | undefined>(defaultContext);\n Context.displayName = rootComponentName + 'Context';\n\n const Provider: React.FC<ContextValueType & { children: React.ReactNode }> = (props) => {\n const { children, ...context } = props;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(consumerName: string) {\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext] as const;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * createContextScope\n * -----------------------------------------------------------------------------------------------*/\n\ntype Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined;\ntype ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope };\ninterface CreateScope {\n scopeName: string;\n (): ScopeHook;\n}\n\nfunction createContextScope(scopeName: string, createContextScopeDeps: CreateScope[] = []) {\n let defaultContexts: any[] = [];\n\n /* -----------------------------------------------------------------------------------------------\n * createContext\n * ---------------------------------------------------------------------------------------------*/\n\n function createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n ) {\n const BaseContext = React.createContext<ContextValueType | undefined>(defaultContext);\n BaseContext.displayName = rootComponentName + 'Context';\n const index = defaultContexts.length;\n defaultContexts = [...defaultContexts, defaultContext];\n\n const Provider: React.FC<\n ContextValueType & { scope: Scope<ContextValueType>; children: React.ReactNode }\n > = (props) => {\n const { scope, children, ...context } = props;\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(consumerName: string, scope: Scope<ContextValueType | undefined>) {\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext] as const;\n }\n\n /* -----------------------------------------------------------------------------------------------\n * createScope\n * ---------------------------------------------------------------------------------------------*/\n\n const createScope: CreateScope = () => {\n const scopeContexts = defaultContexts.map((defaultContext) => {\n return React.createContext(defaultContext);\n });\n return function useScope(scope: Scope) {\n const contexts = scope?.[scopeName] || scopeContexts;\n return React.useMemo(\n () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),\n [scope, contexts],\n );\n };\n };\n\n createScope.scopeName = scopeName;\n return [createContext, composeContextScopes(createScope, ...createContextScopeDeps)] as const;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * composeContextScopes\n * -----------------------------------------------------------------------------------------------*/\n\nfunction composeContextScopes(...scopes: [CreateScope, ...CreateScope[]]): CreateScope {\n const baseScope = scopes[0];\n if (scopes.length === 1) return baseScope;\n\n const createScope: CreateScope = () => {\n const scopeHooks = scopes.map((createScope) => ({\n useScope: createScope(),\n scopeName: createScope.scopeName,\n }));\n\n return function useComposedScopes(overrideScopes) {\n const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {\n // We are calling a hook inside a callback which React warns against to avoid inconsistent\n // renders, however, scoping doesn't have render side effects so we ignore the rule.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const scopeProps = useScope(overrideScopes);\n const currentScope = scopeProps[`__scope${scopeName}`];\n return { ...nextScopes, ...currentScope };\n }, {});\n\n return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);\n };\n };\n\n createScope.scopeName = baseScope.scopeName;\n return createScope;\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nexport { createContext, createContextScope };\nexport type { CreateScope, Scope };\n"],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;AAClC,SAAO;AACT;",
"sourcesContent": ["import * as React from 'react';\n\ntype ContextProvider<ContextValueType extends object | null> = React.FC<\n ContextValueType & {\n children: React.ReactNode;\n }\n>;\n\ninterface UseAssertedContext<ContextValueType extends object | null> {\n (consumerName: string): ContextValueType;\n}\n\ninterface UseContext<ContextValueType extends object | null> {\n (consumerName: string): ContextValueType;\n (consumerName: string, options: { optional: true }): ContextValueType | undefined;\n}\n\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>];\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext: ContextValueType,\n): readonly [ContextProvider<ContextValueType>, UseAssertedContext<ContextValueType>];\n\nfunction createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n): readonly [ContextProvider<ContextValueType>, UseContext<ContextValueType>] {\n const Context = React.createContext<ContextValueType | undefined>(defaultContext);\n Context.displayName = rootComponentName + 'Context';\n\n const Provider: ContextProvider<ContextValueType> = (props) => {\n const { children, ...context } = props;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(consumerName: string): ContextValueType;\n function useContext(\n consumerName: string,\n options: { optional: true },\n ): ContextValueType | undefined;\n\n function useContext(\n consumerName: string,\n options: { optional?: boolean } = {},\n ): ContextValueType | undefined {\n const { optional = false } = options;\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n if (optional) return undefined;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext];\n}\n\n/* -------------------------------------------------------------------------------------------------\n * createContextScope\n * -----------------------------------------------------------------------------------------------*/\n\ntype Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined;\ntype ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope };\ninterface CreateScope {\n scopeName: string;\n (): ScopeHook;\n}\n\ntype ScopedContextProvider<ContextValueType extends object | null> = React.FC<\n ContextValueType & {\n scope: Scope<ContextValueType>;\n children: React.ReactNode;\n }\n>;\n\ninterface UseScopedContext<ContextValueType extends object | null> {\n (consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;\n (\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options: { optional?: true },\n ): ContextValueType | undefined;\n}\n\ninterface UseAssertedScopedContext<ContextValueType extends object | null> {\n (consumerName: string, scope: Scope<ContextValueType | undefined>): ContextValueType;\n}\n\ninterface CreateScopedContext {\n <ContextValueType extends object | null>(\n rootComponentName: string,\n ): readonly [ScopedContextProvider<ContextValueType>, UseScopedContext<ContextValueType>];\n <ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext: ContextValueType,\n ): readonly [ScopedContextProvider<ContextValueType>, UseAssertedScopedContext<ContextValueType>];\n}\n\nfunction createContextScope(\n scopeName: string,\n createContextScopeDeps: CreateScope[] = [],\n): readonly [CreateScopedContext, CreateScope] {\n let defaultContexts: any[] = [];\n\n /* -----------------------------------------------------------------------------------------------\n * createContext\n * ---------------------------------------------------------------------------------------------*/\n\n function createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType,\n ) {\n const BaseContext = React.createContext<ContextValueType | undefined>(defaultContext);\n BaseContext.displayName = rootComponentName + 'Context';\n const index = defaultContexts.length;\n defaultContexts = [...defaultContexts, defaultContext];\n\n const Provider: ScopedContextProvider<ContextValueType> = (props) => {\n const { scope, children, ...context } = props;\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType;\n return <Context.Provider value={value}>{children}</Context.Provider>;\n };\n\n Provider.displayName = rootComponentName + 'Provider';\n\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n ): ContextValueType;\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options: { optional: true },\n ): ContextValueType | undefined;\n\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options: { optional?: boolean } = {},\n ): ContextValueType | undefined {\n const { optional = false } = options;\n const Context = scope?.[scopeName]?.[index] || BaseContext;\n const context = React.useContext(Context);\n if (context) return context;\n if (defaultContext !== undefined) return defaultContext;\n if (optional) return undefined;\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``);\n }\n\n return [Provider, useContext] as const;\n }\n\n /* -----------------------------------------------------------------------------------------------\n * createScope\n * ---------------------------------------------------------------------------------------------*/\n\n const createScope: CreateScope = () => {\n const scopeContexts = defaultContexts.map((defaultContext) => {\n return React.createContext(defaultContext);\n });\n return function useScope(scope: Scope) {\n const contexts = scope?.[scopeName] || scopeContexts;\n return React.useMemo(\n () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),\n [scope, contexts],\n );\n };\n };\n\n createScope.scopeName = scopeName;\n return [createContext, composeContextScopes(createScope, ...createContextScopeDeps)] as const;\n}\n\n/* -------------------------------------------------------------------------------------------------\n * composeContextScopes\n * -----------------------------------------------------------------------------------------------*/\n\nfunction composeContextScopes(...scopes: [CreateScope, ...CreateScope[]]): CreateScope {\n const baseScope = scopes[0];\n if (scopes.length === 1) return baseScope;\n\n const createScope: CreateScope = () => {\n const scopeHooks = scopes.map((createScope) => ({\n useScope: createScope(),\n scopeName: createScope.scopeName,\n }));\n\n return function useComposedScopes(overrideScopes) {\n const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {\n // We are calling a hook inside a callback which React warns against to avoid inconsistent\n // renders, however, scoping doesn't have render side effects so we ignore the rule.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const scopeProps = useScope(overrideScopes);\n const currentScope = scopeProps[`__scope${scopeName}`];\n return { ...nextScopes, ...currentScope };\n }, {});\n\n return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);\n };\n };\n\n createScope.scopeName = baseScope.scopeName;\n return createScope;\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nexport { createContext, createContextScope };\nexport type {\n CreateScope,\n CreateScopedContext,\n Scope,\n UseAssertedContext,\n UseAssertedScopedContext,\n UseContext,\n UseScopedContext,\n};\n"],
"mappings": ";AAAA,YAAY,WAAW;AAqCZ;AAZX,SAASA,eACP,mBACA,gBAC4E;AAC5E,QAAM,UAAgB,oBAA4C,cAAc;AAChF,UAAQ,cAAc,oBAAoB;AAE1C,QAAM,WAA8C,CAAC,UAAU;AAC7D,UAAM,EAAE,UAAU,GAAG,QAAQ,IAAI;AAGjC,UAAM,QAAc,cAAQ,MAAM,SAAS,OAAO,OAAO,OAAO,CAAC;AACjE,WAAO,oBAAC,QAAQ,UAAR,EAAiB,OAAe,UAAS;AAAA,EACnD;AAEA,WAAS,cAAc,oBAAoB;AAQ3C,WAASC,YACP,cACA,UAAkC,CAAC,GACL;AAC9B,UAAM,EAAE,WAAW,MAAM,IAAI;AAC7B,UAAM,UAAgB,iBAAW,OAAO;AACxC,QAAI,QAAS,QAAO;AACpB,QAAI,mBAAmB,OAAW,QAAO;AACzC,QAAI,SAAU,QAAO;AAErB,UAAM,IAAI,MAAM,KAAK,YAAY,4BAA4B,iBAAiB,IAAI;AAAA,EACpF;AAEA,SAAO,CAAC,UAAUA,WAAU;AAC9B;AA2CA,SAAS,mBACP,WACA,yBAAwC,CAAC,GACI;AAC7C,MAAI,kBAAyB,CAAC;AAM9B,WAASD,eACP,mBACA,gBACA;AACA,UAAM,cAAoB,oBAA4C,cAAc;AACpF,gBAAY,cAAc,oBAAoB;AAC9C,UAAM,QAAQ,gBAAgB;AAC9B,sBAAkB,CAAC,GAAG,iBAAiB,cAAc;AAErD,UAAM,WAAoD,CA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BAAiB;AAAA,MAC9C,UAAUA,aAAY;AAAA,MACtB,WAAWA,aAAY;AAAA,IACzB,EAAE;AAEF,WAAO,SAAS,kBAAkB,gBAAgB;AAChD,YAAM,aAAa,WAAW,OAAO,CAACC,aAAY,EAAE,UAAU,UAAU,MAAM;AAI5E,cAAM,aAAa,SAAS,cAAc;AAC1C,cAAM,eAAe,WAAW,UAAU,SAAS,EAAE;AACrD,eAAO,EAAE,GAAGA,aAAY,GAAG,aAAa;AAAA,MAC1C,GAAG,CAAC,CAAC;AAEL,aAAa,cAAQ,OAAO,EAAE,CAAC,UAAU,UAAU,SAAS,EAAE,GAAG,WAAW,IAAI,CAAC,UAAU,CAAC;AAAA,IAC9F;AAAA,EACF;AAEA,cAAY,YAAY,UAAU;AAClC,SAAO;AACT;",
"names": ["createContext", "useContext", "createScope", "nextScopes"]
}
{
"name": "@radix-ui/react-context",
"version": "1.1.4",
"version": "1.2.0-rc.1782930601752",
"license": "MIT",

@@ -5,0 +5,0 @@ "source": "./src/index.ts",