@tamagui/create-context 1.0.1-beta.72 → 1.0.1-beta.73

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.
@@ -21,7 +21,6 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
25
24
  var __objRest = (source, exclude) => {
26
25
  var target = {};
27
26
  for (var prop in source)
@@ -64,7 +63,6 @@ function createContext(rootComponentName, defaultContext) {
64
63
  value
65
64
  }, children);
66
65
  }
67
- __name(Provider, "Provider");
68
66
  function useContext(consumerName) {
69
67
  const context = React.useContext(Context);
70
68
  if (context)
@@ -73,11 +71,9 @@ function createContext(rootComponentName, defaultContext) {
73
71
  return defaultContext;
74
72
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
75
73
  }
76
- __name(useContext, "useContext");
77
74
  Provider.displayName = rootComponentName + "Provider";
78
75
  return [Provider, useContext];
79
76
  }
80
- __name(createContext, "createContext");
81
77
  function createContextScope(scopeName, createContextScopeDeps = []) {
82
78
  let defaultContexts = [];
83
79
  function createContext2(rootComponentName, defaultContext) {
@@ -92,7 +88,6 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
92
88
  value
93
89
  }, children);
94
90
  }
95
- __name(Provider, "Provider");
96
91
  function useContext(consumerName, scope) {
97
92
  const Context = (scope == null ? void 0 : scope[scopeName][index]) || BaseContext;
98
93
  const context = React.useContext(Context);
@@ -102,46 +97,42 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
102
97
  return defaultContext;
103
98
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
104
99
  }
105
- __name(useContext, "useContext");
106
100
  Provider.displayName = rootComponentName + "Provider";
107
101
  return [Provider, useContext];
108
102
  }
109
- __name(createContext2, "createContext");
110
- const createScope = /* @__PURE__ */ __name(() => {
103
+ const createScope = () => {
111
104
  const scopeContexts = defaultContexts.map((defaultContext) => {
112
105
  return React.createContext(defaultContext);
113
106
  });
114
- return /* @__PURE__ */ __name(function useScope(scope) {
107
+ return function useScope(scope) {
115
108
  const contexts = (scope == null ? void 0 : scope[scopeName]) || scopeContexts;
116
109
  return React.useMemo(() => ({ [`__scope${scopeName}`]: __spreadProps(__spreadValues({}, scope), { [scopeName]: contexts }) }), [scope, contexts]);
117
- }, "useScope");
118
- }, "createScope");
110
+ };
111
+ };
119
112
  createScope.scopeName = scopeName;
120
113
  return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
121
114
  }
122
- __name(createContextScope, "createContextScope");
123
115
  function composeContextScopes(...scopes) {
124
116
  const baseScope = scopes[0];
125
117
  if (scopes.length === 1)
126
118
  return baseScope;
127
- const createScope = /* @__PURE__ */ __name(() => {
119
+ const createScope = () => {
128
120
  const scopeHooks = scopes.map((createScope2) => ({
129
121
  useScope: createScope2(),
130
122
  scopeName: createScope2.scopeName
131
123
  }));
132
- return /* @__PURE__ */ __name(function useComposedScopes(overrideScopes) {
124
+ return function useComposedScopes(overrideScopes) {
133
125
  const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
134
126
  const scopeProps = useScope(overrideScopes);
135
127
  const currentScope = scopeProps[`__scope${scopeName}`];
136
128
  return __spreadValues(__spreadValues({}, nextScopes2), currentScope);
137
129
  }, {});
138
130
  return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
139
- }, "useComposedScopes");
140
- }, "createScope");
131
+ };
132
+ };
141
133
  createScope.scopeName = baseScope.scopeName;
142
134
  return createScope;
143
135
  }
144
- __name(composeContextScopes, "composeContextScopes");
145
136
  // Annotate the CommonJS export names for ESM import in node:
146
137
  0 && (module.exports = {
147
138
  createContext,
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/create-context.tsx"],
4
4
  "sourcesContent": ["// from radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/context/src/createContext.tsx\n\nimport * as React from 'react'\n\nexport type ScopedProps<P, K extends string> = P & { [Key in `__scope${K}`]?: Scope }\n\nexport function 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 ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope }\n\nexport type Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined\n\nexport interface CreateScope {\n scopeName: string\n (): ScopeHook\n}\n\nexport function 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/* -----------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;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
1
  import * as React from "react";
4
2
  function createContext(rootComponentName, defaultContext) {
5
3
  const Context = React.createContext(defaultContext);
@@ -10,7 +8,6 @@ function createContext(rootComponentName, defaultContext) {
10
8
  value
11
9
  }, children);
12
10
  }
13
- __name(Provider, "Provider");
14
11
  function useContext(consumerName) {
15
12
  const context = React.useContext(Context);
16
13
  if (context)
@@ -19,11 +16,9 @@ function createContext(rootComponentName, defaultContext) {
19
16
  return defaultContext;
20
17
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
21
18
  }
22
- __name(useContext, "useContext");
23
19
  Provider.displayName = rootComponentName + "Provider";
24
20
  return [Provider, useContext];
25
21
  }
26
- __name(createContext, "createContext");
27
22
  function createContextScope(scopeName, createContextScopeDeps = []) {
28
23
  let defaultContexts = [];
29
24
  function createContext2(rootComponentName, defaultContext) {
@@ -38,7 +33,6 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
38
33
  value
39
34
  }, children);
40
35
  }
41
- __name(Provider, "Provider");
42
36
  function useContext(consumerName, scope) {
43
37
  const Context = (scope == null ? void 0 : scope[scopeName][index]) || BaseContext;
44
38
  const context = React.useContext(Context);
@@ -48,46 +42,42 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
48
42
  return defaultContext;
49
43
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
50
44
  }
51
- __name(useContext, "useContext");
52
45
  Provider.displayName = rootComponentName + "Provider";
53
46
  return [Provider, useContext];
54
47
  }
55
- __name(createContext2, "createContext");
56
- const createScope = /* @__PURE__ */ __name(() => {
48
+ const createScope = () => {
57
49
  const scopeContexts = defaultContexts.map((defaultContext) => {
58
50
  return React.createContext(defaultContext);
59
51
  });
60
- return /* @__PURE__ */ __name(function useScope(scope) {
52
+ return function useScope(scope) {
61
53
  const contexts = (scope == null ? void 0 : scope[scopeName]) || scopeContexts;
62
54
  return React.useMemo(() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }), [scope, contexts]);
63
- }, "useScope");
64
- }, "createScope");
55
+ };
56
+ };
65
57
  createScope.scopeName = scopeName;
66
58
  return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
67
59
  }
68
- __name(createContextScope, "createContextScope");
69
60
  function composeContextScopes(...scopes) {
70
61
  const baseScope = scopes[0];
71
62
  if (scopes.length === 1)
72
63
  return baseScope;
73
- const createScope = /* @__PURE__ */ __name(() => {
64
+ const createScope = () => {
74
65
  const scopeHooks = scopes.map((createScope2) => ({
75
66
  useScope: createScope2(),
76
67
  scopeName: createScope2.scopeName
77
68
  }));
78
- return /* @__PURE__ */ __name(function useComposedScopes(overrideScopes) {
69
+ return function useComposedScopes(overrideScopes) {
79
70
  const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
80
71
  const scopeProps = useScope(overrideScopes);
81
72
  const currentScope = scopeProps[`__scope${scopeName}`];
82
73
  return { ...nextScopes2, ...currentScope };
83
74
  }, {});
84
75
  return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
85
- }, "useComposedScopes");
86
- }, "createScope");
76
+ };
77
+ };
87
78
  createScope.scopeName = baseScope.scopeName;
88
79
  return createScope;
89
80
  }
90
- __name(composeContextScopes, "composeContextScopes");
91
81
  export {
92
82
  createContext,
93
83
  createContextScope
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/create-context.tsx"],
4
4
  "sourcesContent": ["// from radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/context/src/createContext.tsx\n\nimport * as React from 'react'\n\nexport type ScopedProps<P, K extends string> = P & { [Key in `__scope${K}`]?: Scope }\n\nexport function 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 ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope }\n\nexport type Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined\n\nexport interface CreateScope {\n scopeName: string\n (): ScopeHook\n}\n\nexport function 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"],
5
- "mappings": ";;AAGA;AAIO,uBACL,mBACA,gBACA;AACA,QAAM,UAAU,MAAM,cAA4C,cAAc;AAEhF,oBAAkB,OAAyD;AACzE,UAAM,EAAE,aAAa,YAAY;AAGjC,UAAM,QAAQ,MAAM,QAAQ,MAAM,SAAS,OA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E,IACtE,CAAC,OAAO,QAAQ,CAClB;AAAA,IACF;AAAA,EACF;AAEA,cAAY,YAAY;AACxB,SAAO,CAAC,gBAAe,qBAAqB,aAAa,GAAG,sBAAsB,CAAC;AACrF;AAMA,iCAAiC,QAAuB;AACtD,QAAM,YAAY,OAAO;AACzB,MAAI,OAAO,WAAW;AAAG,WAAO;AAEhC,QAAM,cAA2B,MAAM;AACrC,UAAM,aAAa,OAAO,IAAI,CAAC,iBAAiB;AAAA,MAC9C,UAAU,aAAY;AAAA,MACtB,WAAW,aAAY;AAAA,IACzB,EAAE;AAEF,WAAO,2BAA2B,gBAAgB;AAChD,YAAM,aAAa,WAAW,OAAO,CAAC,aAAY,EAAE,UAAU,gBAAgB;AAI5E,cAAM,aAAa,SAAS,cAAc;AAC1C,cAAM,eAAe,WAAW,UAAU;AAC1C,eAAO,EAAE,GAAG,aAAY,GAAG,aAAa;AAAA,MAC1C,GAAG,CAAC,CAAC;AAEL,aAAO,MAAM,QAAQ,MAAO,GAAE,CAAC,UAAU,UAAU,cAAc,WAAW,IAAI,CAAC,UAAU,CAAC;AAAA,IAC9F;AAAA,EACF;AAEA,cAAY,YAAY,UAAU;AAClC,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,5 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
1
  import * as React from "react";
4
2
  function createContext(rootComponentName, defaultContext) {
5
3
  const Context = React.createContext(defaultContext);
@@ -8,7 +6,6 @@ function createContext(rootComponentName, defaultContext) {
8
6
  const value = React.useMemo(() => context, Object.values(context));
9
7
  return <Context.Provider value={value}>{children}</Context.Provider>;
10
8
  }
11
- __name(Provider, "Provider");
12
9
  function useContext(consumerName) {
13
10
  const context = React.useContext(Context);
14
11
  if (context)
@@ -17,11 +14,9 @@ function createContext(rootComponentName, defaultContext) {
17
14
  return defaultContext;
18
15
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
19
16
  }
20
- __name(useContext, "useContext");
21
17
  Provider.displayName = rootComponentName + "Provider";
22
18
  return [Provider, useContext];
23
19
  }
24
- __name(createContext, "createContext");
25
20
  function createContextScope(scopeName, createContextScopeDeps = []) {
26
21
  let defaultContexts = [];
27
22
  function createContext2(rootComponentName, defaultContext) {
@@ -34,7 +29,6 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
34
29
  const value = React.useMemo(() => context, Object.values(context));
35
30
  return <Context.Provider value={value}>{children}</Context.Provider>;
36
31
  }
37
- __name(Provider, "Provider");
38
32
  function useContext(consumerName, scope) {
39
33
  const Context = (scope == null ? void 0 : scope[scopeName][index]) || BaseContext;
40
34
  const context = React.useContext(Context);
@@ -44,46 +38,42 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
44
38
  return defaultContext;
45
39
  throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
46
40
  }
47
- __name(useContext, "useContext");
48
41
  Provider.displayName = rootComponentName + "Provider";
49
42
  return [Provider, useContext];
50
43
  }
51
- __name(createContext2, "createContext");
52
- const createScope = /* @__PURE__ */ __name(() => {
44
+ const createScope = () => {
53
45
  const scopeContexts = defaultContexts.map((defaultContext) => {
54
46
  return React.createContext(defaultContext);
55
47
  });
56
- return /* @__PURE__ */ __name(function useScope(scope) {
48
+ return function useScope(scope) {
57
49
  const contexts = (scope == null ? void 0 : scope[scopeName]) || scopeContexts;
58
50
  return React.useMemo(() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }), [scope, contexts]);
59
- }, "useScope");
60
- }, "createScope");
51
+ };
52
+ };
61
53
  createScope.scopeName = scopeName;
62
54
  return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
63
55
  }
64
- __name(createContextScope, "createContextScope");
65
56
  function composeContextScopes(...scopes) {
66
57
  const baseScope = scopes[0];
67
58
  if (scopes.length === 1)
68
59
  return baseScope;
69
- const createScope = /* @__PURE__ */ __name(() => {
60
+ const createScope = () => {
70
61
  const scopeHooks = scopes.map((createScope2) => ({
71
62
  useScope: createScope2(),
72
63
  scopeName: createScope2.scopeName
73
64
  }));
74
- return /* @__PURE__ */ __name(function useComposedScopes(overrideScopes) {
65
+ return function useComposedScopes(overrideScopes) {
75
66
  const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
76
67
  const scopeProps = useScope(overrideScopes);
77
68
  const currentScope = scopeProps[`__scope${scopeName}`];
78
69
  return { ...nextScopes2, ...currentScope };
79
70
  }, {});
80
71
  return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
81
- }, "useComposedScopes");
82
- }, "createScope");
72
+ };
73
+ };
83
74
  createScope.scopeName = baseScope.scopeName;
84
75
  return createScope;
85
76
  }
86
- __name(composeContextScopes, "composeContextScopes");
87
77
  export {
88
78
  createContext,
89
79
  createContextScope
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/create-context",
3
- "version": "1.0.1-beta.72",
3
+ "version": "1.0.1-beta.73",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  "react": "*"
21
21
  },
22
22
  "devDependencies": {
23
- "@tamagui/build": "^1.0.1-beta.72",
23
+ "@tamagui/build": "^1.0.1-beta.73",
24
24
  "react": "*"
25
25
  },
26
26
  "publishConfig": {