@radix-ui/react-context 1.1.0-rc.2 → 1.1.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,15 +1,16 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
1
2
  import * as React from 'react';
2
3
 
3
4
  declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType): readonly [{
4
5
  (props: ContextValueType & {
5
6
  children: React.ReactNode;
6
- }): JSX.Element;
7
+ }): react_jsx_runtime.JSX.Element;
7
8
  displayName: string;
8
9
  }, (consumerName: string) => ContextValueType];
9
- declare type Scope<C = any> = {
10
+ type Scope<C = any> = {
10
11
  [scopeName: string]: React.Context<C>[];
11
12
  } | undefined;
12
- declare type ScopeHook = (scope: Scope) => {
13
+ type ScopeHook = (scope: Scope) => {
13
14
  [__scopeProp: string]: Scope;
14
15
  };
15
16
  interface CreateScope {
@@ -20,7 +21,7 @@ declare function createContextScope(scopeName: string, createContextScopeDeps?:
20
21
  (props: ContextValueType & {
21
22
  scope: Scope<ContextValueType>;
22
23
  children: React.ReactNode;
23
- }): JSX.Element;
24
+ }): react_jsx_runtime.JSX.Element;
24
25
  displayName: string;
25
26
  }, (consumerName: string, scope: Scope<ContextValueType | undefined>) => ContextValueType], CreateScope];
26
27
 
package/dist/index.d.ts CHANGED
@@ -1,15 +1,16 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
1
2
  import * as React from 'react';
2
3
 
3
4
  declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType): readonly [{
4
5
  (props: ContextValueType & {
5
6
  children: React.ReactNode;
6
- }): JSX.Element;
7
+ }): react_jsx_runtime.JSX.Element;
7
8
  displayName: string;
8
9
  }, (consumerName: string) => ContextValueType];
9
- declare type Scope<C = any> = {
10
+ type Scope<C = any> = {
10
11
  [scopeName: string]: React.Context<C>[];
11
12
  } | undefined;
12
- declare type ScopeHook = (scope: Scope) => {
13
+ type ScopeHook = (scope: Scope) => {
13
14
  [__scopeProp: string]: Scope;
14
15
  };
15
16
  interface CreateScope {
@@ -20,7 +21,7 @@ declare function createContextScope(scopeName: string, createContextScopeDeps?:
20
21
  (props: ContextValueType & {
21
22
  scope: Scope<ContextValueType>;
22
23
  children: React.ReactNode;
23
- }): JSX.Element;
24
+ }): react_jsx_runtime.JSX.Element;
24
25
  displayName: string;
25
26
  }, (consumerName: string, scope: Scope<ContextValueType | undefined>) => ContextValueType], CreateScope];
26
27
 
package/dist/index.js CHANGED
@@ -1,45 +1,73 @@
1
1
  "use strict";
2
- (() => {
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
29
 
32
- // packages/react/context/src/createContext.tsx
33
- var React = __toESM(__require("react"));
34
- var import_jsx_runtime = __require("react/jsx-runtime");
35
- function createContext2(rootComponentName, defaultContext) {
36
- const Context = React.createContext(defaultContext);
30
+ // packages/react/context/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ createContext: () => createContext2,
34
+ createContextScope: () => createContextScope
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // packages/react/context/src/createContext.tsx
39
+ var React = __toESM(require("react"));
40
+ var import_jsx_runtime = require("react/jsx-runtime");
41
+ function createContext2(rootComponentName, defaultContext) {
42
+ const Context = React.createContext(defaultContext);
43
+ function Provider(props) {
44
+ const { children, ...context } = props;
45
+ const value = React.useMemo(() => context, Object.values(context));
46
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, { value, children });
47
+ }
48
+ function useContext2(consumerName) {
49
+ const context = React.useContext(Context);
50
+ if (context) return context;
51
+ if (defaultContext !== void 0) return defaultContext;
52
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
53
+ }
54
+ Provider.displayName = rootComponentName + "Provider";
55
+ return [Provider, useContext2];
56
+ }
57
+ function createContextScope(scopeName, createContextScopeDeps = []) {
58
+ let defaultContexts = [];
59
+ function createContext3(rootComponentName, defaultContext) {
60
+ const BaseContext = React.createContext(defaultContext);
61
+ const index = defaultContexts.length;
62
+ defaultContexts = [...defaultContexts, defaultContext];
37
63
  function Provider(props) {
38
- const { children, ...context } = props;
64
+ const { scope, children, ...context } = props;
65
+ const Context = scope?.[scopeName][index] || BaseContext;
39
66
  const value = React.useMemo(() => context, Object.values(context));
40
67
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, { value, children });
41
68
  }
42
- function useContext2(consumerName) {
69
+ function useContext2(consumerName, scope) {
70
+ const Context = scope?.[scopeName][index] || BaseContext;
43
71
  const context = React.useContext(Context);
44
72
  if (context) return context;
45
73
  if (defaultContext !== void 0) return defaultContext;
@@ -48,62 +76,39 @@
48
76
  Provider.displayName = rootComponentName + "Provider";
49
77
  return [Provider, useContext2];
50
78
  }
51
- function createContextScope(scopeName, createContextScopeDeps = []) {
52
- let defaultContexts = [];
53
- function createContext3(rootComponentName, defaultContext) {
54
- const BaseContext = React.createContext(defaultContext);
55
- const index = defaultContexts.length;
56
- defaultContexts = [...defaultContexts, defaultContext];
57
- function Provider(props) {
58
- const { scope, children, ...context } = props;
59
- const Context = scope?.[scopeName][index] || BaseContext;
60
- const value = React.useMemo(() => context, Object.values(context));
61
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, { value, children });
62
- }
63
- function useContext2(consumerName, scope) {
64
- const Context = scope?.[scopeName][index] || BaseContext;
65
- const context = React.useContext(Context);
66
- if (context) return context;
67
- if (defaultContext !== void 0) return defaultContext;
68
- throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
69
- }
70
- Provider.displayName = rootComponentName + "Provider";
71
- return [Provider, useContext2];
72
- }
73
- const createScope = () => {
74
- const scopeContexts = defaultContexts.map((defaultContext) => {
75
- return React.createContext(defaultContext);
76
- });
77
- return function useScope(scope) {
78
- const contexts = scope?.[scopeName] || scopeContexts;
79
- return React.useMemo(
80
- () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
81
- [scope, contexts]
82
- );
83
- };
79
+ const createScope = () => {
80
+ const scopeContexts = defaultContexts.map((defaultContext) => {
81
+ return React.createContext(defaultContext);
82
+ });
83
+ return function useScope(scope) {
84
+ const contexts = scope?.[scopeName] || scopeContexts;
85
+ return React.useMemo(
86
+ () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
87
+ [scope, contexts]
88
+ );
84
89
  };
85
- createScope.scopeName = scopeName;
86
- return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
87
- }
88
- function composeContextScopes(...scopes) {
89
- const baseScope = scopes[0];
90
- if (scopes.length === 1) return baseScope;
91
- const createScope = () => {
92
- const scopeHooks = scopes.map((createScope2) => ({
93
- useScope: createScope2(),
94
- scopeName: createScope2.scopeName
95
- }));
96
- return function useComposedScopes(overrideScopes) {
97
- const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
98
- const scopeProps = useScope(overrideScopes);
99
- const currentScope = scopeProps[`__scope${scopeName}`];
100
- return { ...nextScopes2, ...currentScope };
101
- }, {});
102
- return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
103
- };
90
+ };
91
+ createScope.scopeName = scopeName;
92
+ return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
93
+ }
94
+ function composeContextScopes(...scopes) {
95
+ const baseScope = scopes[0];
96
+ if (scopes.length === 1) return baseScope;
97
+ const createScope = () => {
98
+ const scopeHooks = scopes.map((createScope2) => ({
99
+ useScope: createScope2(),
100
+ scopeName: createScope2.scopeName
101
+ }));
102
+ return function useComposedScopes(overrideScopes) {
103
+ const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
104
+ const scopeProps = useScope(overrideScopes);
105
+ const currentScope = scopeProps[`__scope${scopeName}`];
106
+ return { ...nextScopes2, ...currentScope };
107
+ }, {});
108
+ return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
104
109
  };
105
- createScope.scopeName = baseScope.scopeName;
106
- return createScope;
107
- }
108
- })();
110
+ };
111
+ createScope.scopeName = baseScope.scopeName;
112
+ return createScope;
113
+ }
109
114
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/createContext.tsx"],
4
- "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\n function Provider(props: ContextValueType & { children: React.ReactNode }) {\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 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 Provider.displayName = rootComponentName + 'Provider';\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 const index = defaultContexts.length;\n defaultContexts = [...defaultContexts, defaultContext];\n\n function Provider(\n props: ContextValueType & { scope: Scope<ContextValueType>; children: React.ReactNode }\n ) {\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 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 Provider.displayName = rootComponentName + 'Provider';\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[]) {\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,cAAuB;AAaZ;AAXX,WAASA,eACP,mBACA,gBACA;AACA,UAAM,UAAgB,oBAA4C,cAAc;AAEhF,aAAS,SAAS,OAAyD;AACzE,YAAM,EAAE,UAAU,GAAG,QAAQ,IAAI;AAGjC,YAAM,QAAc,cAAQ,MAAM,SAAS,OAAO,OAAO,OAAO,CAAC;AACjE,aAAO,4CAAC,QAAQ,UAAR,EAAiB,OAAe,UAAS;AAAA,IACnD;AAEA,aAASC,YAAW,cAAsB;AACxC,YAAM,UAAgB,iBAAW,OAAO;AACxC,UAAI,QAAS,QAAO;AACpB,UAAI,mBAAmB,OAAW,QAAO;AAEzC,YAAM,IAAI,MAAM,KAAK,YAAY,4BAA4B,iBAAiB,IAAI;AAAA,IACpF;AAEA,aAAS,cAAc,oB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AAqB,aAAa,GAAG,sBAAsB,CAAC;AAAA,EACrF;AAMA,WAAS,wBAAwB,QAAuB;AACtD,UAAM,YAAY,OAAO,CAAC;AAC1B,QAAI,OAAO,WAAW,EAAG,QAAO;AAEhC,UAAM,cAA2B,MAAM;AACrC,YAAM,aAAa,OAAO,IAAI,CAACE,kBAAiB;AAAA,QAC9C,UAAUA,aAAY;AAAA,QACtB,WAAWA,aAAY;AAAA,MACzB,EAAE;AAEF,aAAO,SAAS,kBAAkB,gBAAgB;AAChD,cAAM,aAAa,WAAW,OAAO,CAACC,aAAY,EAAE,UAAU,UAAU,MAAM;AAI5E,gBAAM,aAAa,SAAS,cAAc;AAC1C,gBAAM,eAAe,WAAW,UAAU,SAAS,EAAE;AACrD,iBAAO,EAAE,GAAGA,aAAY,GAAG,aAAa;AAAA,QAC1C,GAAG,CAAC,CAAC;AAEL,eAAa,cAAQ,OAAO,EAAE,CAAC,UAAU,UAAU,SAAS,EAAE,GAAG,WAAW,IAAI,CAAC,UAAU,CAAC;AAAA,MAC9F;AAAA,IACF;AAEA,gBAAY,YAAY,UAAU;AAClC,WAAO;AAAA,EACT;",
6
- "names": ["createContext", "useContext", "createScope", "nextScopes"]
3
+ "sources": ["../src/index.ts", "../src/createContext.tsx"],
4
+ "sourcesContent": ["export { createContext, createContextScope } from './createContext';\nexport type { CreateScope, Scope } from './createContext';\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\n function Provider(props: ContextValueType & { children: React.ReactNode }) {\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 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 Provider.displayName = rootComponentName + 'Provider';\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 const index = defaultContexts.length;\n defaultContexts = [...defaultContexts, defaultContext];\n\n function Provider(\n props: ContextValueType & { scope: Scope<ContextValueType>; children: React.ReactNode }\n ) {\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 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 Provider.displayName = rootComponentName + 'Provider';\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[]) {\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,uBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,YAAuB;AAaZ;AAXX,SAASC,eACP,mBACA,gBACA;AACA,QAAM,UAAgB,oBAA4C,cAAc;AAEhF,WAAS,SAAS,OAAyD;AACzE,UAAM,EAAE,UAAU,GAAG,QAAQ,IAAI;AAGjC,UAAM,QAAc,cAAQ,MAAM,SAAS,OAAO,OAAO,OAAO,CAAC;AACjE,WAAO,4CAAC,QAAQ,UAAR,EAAiB,OAAe,UAAS;A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AAA,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,QAAuB;AACtD,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;",
6
+ "names": ["createContext", "createContext", "useContext", "createScope", "nextScopes"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radix-ui/react-context",
3
- "version": "1.1.0-rc.2",
3
+ "version": "1.1.0-rc.4",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@types/react": "*",
32
- "react": "^16.8 || ^17.0 || ^18.0"
32
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@types/react": {