@tamagui/create-context 2.7.7 → 3.0.0-beta.1097.1

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.
@@ -5,138 +5,117 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var create_context_exports = {};
35
28
  __export(create_context_exports, {
36
- createContext: () => createContext,
37
- createContextScope: () => createContextScope
29
+ createContext: () => createContext,
30
+ createContextScope: () => createContextScope
38
31
  });
39
32
  module.exports = __toCommonJS(create_context_exports);
40
33
  var React = __toESM(require("react"), 1);
41
34
  var import_jsx_runtime = require("react/jsx-runtime");
42
35
  function createContext(rootComponentName, defaultContext) {
43
- const Context = React.createContext(defaultContext);
44
- function Provider(props) {
45
- const {
46
- children,
47
- ...context
48
- } = props;
49
- const value = React.useMemo(() => context, Object.values(context));
50
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
51
- value,
52
- children
53
- });
54
- }
55
- function useContext(consumerName) {
56
- const context = React.useContext(Context);
57
- if (context) return context;
58
- if (defaultContext !== void 0) return defaultContext;
59
- throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
60
- }
61
- return [Provider, useContext];
36
+ const Context = React.createContext(defaultContext);
37
+ function Provider(props) {
38
+ const { children, ...context } = props;
39
+ const value = React.useMemo(() => context, Object.values(context));
40
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
41
+ value,
42
+ children
43
+ });
44
+ }
45
+ function useContext(consumerName) {
46
+ const context = React.useContext(Context);
47
+ if (context) return context;
48
+ if (defaultContext !== void 0) return defaultContext;
49
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
50
+ }
51
+ return [Provider, useContext];
62
52
  }
63
53
  function createContextScope(scopeName, createContextScopeDeps = []) {
64
- let defaultContexts = [];
65
- function createContext2(rootComponentName, defaultContext) {
66
- const BaseContext = React.createContext(defaultContext);
67
- const index = defaultContexts.length;
68
- defaultContexts = [...defaultContexts, defaultContext];
69
- function Provider(props) {
70
- const {
71
- scope,
72
- children,
73
- ...context
74
- } = props;
75
- const Context = scope?.[scopeName]?.[index] || BaseContext;
76
- const value = React.useMemo(() => context, Object.values(context));
77
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
78
- value,
79
- children
80
- });
81
- }
82
- function useContext(consumerName, scope, options) {
83
- const Context = scope?.[scopeName]?.[index] || BaseContext;
84
- const context = React.useContext(Context);
85
- if (context) return context;
86
- if (defaultContext !== void 0) return defaultContext;
87
- const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
88
- if (options?.fallback) {
89
- if (options?.warn !== false) {
90
- console.warn(missingContextMessage);
91
- }
92
- return options.fallback;
93
- }
94
- throw new Error(missingContextMessage);
95
- }
96
- return [Provider, useContext];
97
- }
98
- const createScope = () => {
99
- const scopeContexts = defaultContexts.map(defaultContext => {
100
- return React.createContext(defaultContext);
101
- });
102
- return function useScope(scope) {
103
- const contexts = scope?.[scopeName] || scopeContexts;
104
- return React.useMemo(() => ({
105
- [`__scope${scopeName}`]: {
106
- ...scope,
107
- [scopeName]: contexts
108
- }
109
- }), [scope, contexts]);
110
- };
111
- };
112
- createScope.scopeName = scopeName;
113
- return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
54
+ let defaultContexts = [];
55
+ function createContext2(rootComponentName, defaultContext) {
56
+ const BaseContext = React.createContext(defaultContext);
57
+ const index = defaultContexts.length;
58
+ defaultContexts = [...defaultContexts, defaultContext];
59
+ function Provider(props) {
60
+ const { scope, children, ...context } = props;
61
+ const Context = scope?.[scopeName]?.[index] || BaseContext;
62
+ const value = React.useMemo(() => context, Object.values(context));
63
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
64
+ value,
65
+ children
66
+ });
67
+ }
68
+ function useContext(consumerName, scope, options) {
69
+ const Context = scope?.[scopeName]?.[index] || BaseContext;
70
+ const context = React.useContext(Context);
71
+ if (context) return context;
72
+ if (defaultContext !== void 0) return defaultContext;
73
+ const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
74
+ if (options?.fallback) {
75
+ if (options?.warn !== false) {
76
+ console.warn(missingContextMessage);
77
+ }
78
+ return options.fallback;
79
+ }
80
+ throw new Error(missingContextMessage);
81
+ }
82
+ return [Provider, useContext];
83
+ }
84
+ const createScope = () => {
85
+ const scopeContexts = defaultContexts.map((defaultContext) => {
86
+ return React.createContext(defaultContext);
87
+ });
88
+ return function useScope(scope) {
89
+ const contexts = scope?.[scopeName] || scopeContexts;
90
+ return React.useMemo(() => ({ [`__scope${scopeName}`]: {
91
+ ...scope,
92
+ [scopeName]: contexts
93
+ } }), [scope, contexts]);
94
+ };
95
+ };
96
+ createScope.scopeName = scopeName;
97
+ return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
114
98
  }
115
99
  function composeContextScopes(...scopes) {
116
- const baseScope = scopes[0];
117
- if (scopes.length === 1) return baseScope;
118
- const createScope = () => {
119
- const scopeHooks = scopes.map(createScope2 => ({
120
- useScope: createScope2(),
121
- scopeName: createScope2.scopeName
122
- }));
123
- return function useComposedScopes(overrideScopes) {
124
- const nextScopes = scopeHooks.reduce((nextScopes2, {
125
- useScope,
126
- scopeName
127
- }) => {
128
- const scopeProps = useScope(overrideScopes);
129
- const currentScope = scopeProps[`__scope${scopeName}`];
130
- return {
131
- ...nextScopes2,
132
- ...currentScope
133
- };
134
- }, {});
135
- return React.useMemo(() => ({
136
- [`__scope${baseScope.scopeName}`]: nextScopes
137
- }), [nextScopes]);
138
- };
139
- };
140
- createScope.scopeName = baseScope.scopeName;
141
- return createScope;
142
- }
100
+ const baseScope = scopes[0];
101
+ if (scopes.length === 1) return baseScope;
102
+ const createScope = () => {
103
+ const scopeHooks = scopes.map((createScope2) => ({
104
+ useScope: createScope2(),
105
+ scopeName: createScope2.scopeName
106
+ }));
107
+ return function useComposedScopes(overrideScopes) {
108
+ const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
109
+ const scopeProps = useScope(overrideScopes);
110
+ const currentScope = scopeProps[`__scope${scopeName}`];
111
+ return {
112
+ ...nextScopes2,
113
+ ...currentScope
114
+ };
115
+ }, {});
116
+ return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
117
+ };
118
+ };
119
+ createScope.scopeName = baseScope.scopeName;
120
+ return createScope;
121
+ }
@@ -0,0 +1,140 @@
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 __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var create_context_exports = {};
30
+ __export(create_context_exports, {
31
+ createContext: () => createContext,
32
+ createContextScope: () => createContextScope
33
+ });
34
+ module.exports = __toCommonJS(create_context_exports);
35
+ var import_jsx_runtime = require("react/jsx-runtime");
36
+ var React = __toESM(require("react"), 1);
37
+ function createContext(rootComponentName, defaultContext) {
38
+ var Context = /* @__PURE__ */ React.createContext(defaultContext);
39
+ function Provider(props) {
40
+ var { children, ...context } = props;
41
+ var value = React.useMemo(function() {
42
+ return context;
43
+ }, Object.values(context));
44
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
45
+ value,
46
+ children
47
+ });
48
+ }
49
+ function useContext(consumerName) {
50
+ var context = React.useContext(Context);
51
+ if (context) return context;
52
+ if (defaultContext !== void 0) return defaultContext;
53
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
54
+ }
55
+ return [Provider, useContext];
56
+ }
57
+ function createContextScope(scopeName) {
58
+ var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
59
+ var defaultContexts = [];
60
+ function createContext2(rootComponentName, defaultContext) {
61
+ var BaseContext = /* @__PURE__ */ React.createContext(defaultContext);
62
+ var index = defaultContexts.length;
63
+ defaultContexts = [...defaultContexts, defaultContext];
64
+ function Provider(props) {
65
+ var _scope_scopeName;
66
+ var { scope, children, ...context } = props;
67
+ var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
68
+ var value = React.useMemo(function() {
69
+ return context;
70
+ }, Object.values(context));
71
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
72
+ value,
73
+ children
74
+ });
75
+ }
76
+ function useContext(consumerName, scope, options) {
77
+ var _scope_scopeName;
78
+ var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
79
+ var context = React.useContext(Context);
80
+ if (context) return context;
81
+ if (defaultContext !== void 0) return defaultContext;
82
+ var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
83
+ if (options === null || options === void 0 ? void 0 : options.fallback) {
84
+ if ((options === null || options === void 0 ? void 0 : options.warn) !== false) {
85
+ console.warn(missingContextMessage);
86
+ }
87
+ return options.fallback;
88
+ }
89
+ throw new Error(missingContextMessage);
90
+ }
91
+ return [Provider, useContext];
92
+ }
93
+ var createScope = function() {
94
+ var scopeContexts = defaultContexts.map(function(defaultContext) {
95
+ return /* @__PURE__ */ React.createContext(defaultContext);
96
+ });
97
+ return function useScope(scope) {
98
+ var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
99
+ return React.useMemo(function() {
100
+ return { [`__scope${scopeName}`]: {
101
+ ...scope,
102
+ [scopeName]: contexts
103
+ } };
104
+ }, [scope, contexts]);
105
+ };
106
+ };
107
+ createScope.scopeName = scopeName;
108
+ return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
109
+ }
110
+ function composeContextScopes() {
111
+ for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
112
+ scopes[_key] = arguments[_key];
113
+ }
114
+ var baseScope = scopes[0];
115
+ if (scopes.length === 1) return baseScope;
116
+ var createScope = function() {
117
+ var scopeHooks = scopes.map(function(createScope2) {
118
+ return {
119
+ useScope: createScope2(),
120
+ scopeName: createScope2.scopeName
121
+ };
122
+ });
123
+ return function useComposedScopes(overrideScopes) {
124
+ var nextScopes = scopeHooks.reduce(function(nextScopes2, param) {
125
+ var { useScope, scopeName } = param;
126
+ var scopeProps = useScope(overrideScopes);
127
+ var currentScope = scopeProps[`__scope${scopeName}`];
128
+ return {
129
+ ...nextScopes2,
130
+ ...currentScope
131
+ };
132
+ }, {});
133
+ return React.useMemo(function() {
134
+ return { [`__scope${baseScope.scopeName}`]: nextScopes };
135
+ }, [nextScopes]);
136
+ };
137
+ };
138
+ createScope.scopeName = baseScope.scopeName;
139
+ return createScope;
140
+ }
@@ -7,156 +7,136 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
14
  };
15
15
  var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
- get: () => from[key],
19
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
- });
21
- }
22
- return to;
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
23
  };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
30
- value: mod,
31
- enumerable: true
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
32
27
  }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
29
  var create_context_exports = {};
37
30
  __export(create_context_exports, {
38
- createContext: () => createContext,
39
- createContextScope: () => createContextScope
31
+ createContext: () => createContext,
32
+ createContextScope: () => createContextScope
40
33
  });
41
34
  module.exports = __toCommonJS(create_context_exports);
42
35
  var import_jsx_runtime = require("react/jsx-runtime");
43
36
  var React = __toESM(require("react"), 1);
44
37
  function createContext(rootComponentName, defaultContext) {
45
- var Context = /* @__PURE__ */React.createContext(defaultContext);
46
- function Provider(props) {
47
- var {
48
- children,
49
- ...context
50
- } = props;
51
- var value = React.useMemo(function () {
52
- return context;
53
- }, Object.values(context));
54
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
55
- value,
56
- children
57
- });
58
- }
59
- function useContext(consumerName) {
60
- var context = React.useContext(Context);
61
- if (context) return context;
62
- if (defaultContext !== void 0) return defaultContext;
63
- throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
64
- }
65
- return [Provider, useContext];
38
+ var Context = /* @__PURE__ */ React.createContext(defaultContext);
39
+ function Provider(props) {
40
+ var { children, ...context } = props;
41
+ var value = React.useMemo(function() {
42
+ return context;
43
+ }, Object.values(context));
44
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
45
+ value,
46
+ children
47
+ });
48
+ }
49
+ function useContext(consumerName) {
50
+ var context = React.useContext(Context);
51
+ if (context) return context;
52
+ if (defaultContext !== void 0) return defaultContext;
53
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
54
+ }
55
+ return [Provider, useContext];
66
56
  }
67
57
  function createContextScope(scopeName) {
68
- var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
69
- var defaultContexts = [];
70
- function createContext2(rootComponentName, defaultContext) {
71
- var BaseContext = /* @__PURE__ */React.createContext(defaultContext);
72
- var index = defaultContexts.length;
73
- defaultContexts = [...defaultContexts, defaultContext];
74
- function Provider(props) {
75
- var _scope_scopeName;
76
- var {
77
- scope,
78
- children,
79
- ...context
80
- } = props;
81
- var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
82
- var value = React.useMemo(function () {
83
- return context;
84
- }, Object.values(context));
85
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
86
- value,
87
- children
88
- });
89
- }
90
- function useContext(consumerName, scope, options) {
91
- var _scope_scopeName;
92
- var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
93
- var context = React.useContext(Context);
94
- if (context) return context;
95
- if (defaultContext !== void 0) return defaultContext;
96
- var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
97
- if (options === null || options === void 0 ? void 0 : options.fallback) {
98
- if ((options === null || options === void 0 ? void 0 : options.warn) !== false) {
99
- console.warn(missingContextMessage);
100
- }
101
- return options.fallback;
102
- }
103
- throw new Error(missingContextMessage);
104
- }
105
- return [Provider, useContext];
106
- }
107
- var createScope = function () {
108
- var scopeContexts = defaultContexts.map(function (defaultContext) {
109
- return /* @__PURE__ */React.createContext(defaultContext);
110
- });
111
- return function useScope(scope) {
112
- var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
113
- return React.useMemo(function () {
114
- return {
115
- [`__scope${scopeName}`]: {
116
- ...scope,
117
- [scopeName]: contexts
118
- }
119
- };
120
- }, [scope, contexts]);
121
- };
122
- };
123
- createScope.scopeName = scopeName;
124
- return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
58
+ var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
59
+ var defaultContexts = [];
60
+ function createContext2(rootComponentName, defaultContext) {
61
+ var BaseContext = /* @__PURE__ */ React.createContext(defaultContext);
62
+ var index = defaultContexts.length;
63
+ defaultContexts = [...defaultContexts, defaultContext];
64
+ function Provider(props) {
65
+ var _scope_scopeName;
66
+ var { scope, children, ...context } = props;
67
+ var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
68
+ var value = React.useMemo(function() {
69
+ return context;
70
+ }, Object.values(context));
71
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
72
+ value,
73
+ children
74
+ });
75
+ }
76
+ function useContext(consumerName, scope, options) {
77
+ var _scope_scopeName;
78
+ var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
79
+ var context = React.useContext(Context);
80
+ if (context) return context;
81
+ if (defaultContext !== void 0) return defaultContext;
82
+ var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
83
+ if (options === null || options === void 0 ? void 0 : options.fallback) {
84
+ if ((options === null || options === void 0 ? void 0 : options.warn) !== false) {
85
+ console.warn(missingContextMessage);
86
+ }
87
+ return options.fallback;
88
+ }
89
+ throw new Error(missingContextMessage);
90
+ }
91
+ return [Provider, useContext];
92
+ }
93
+ var createScope = function() {
94
+ var scopeContexts = defaultContexts.map(function(defaultContext) {
95
+ return /* @__PURE__ */ React.createContext(defaultContext);
96
+ });
97
+ return function useScope(scope) {
98
+ var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
99
+ return React.useMemo(function() {
100
+ return { [`__scope${scopeName}`]: {
101
+ ...scope,
102
+ [scopeName]: contexts
103
+ } };
104
+ }, [scope, contexts]);
105
+ };
106
+ };
107
+ createScope.scopeName = scopeName;
108
+ return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
125
109
  }
126
110
  function composeContextScopes() {
127
- for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
128
- scopes[_key] = arguments[_key];
129
- }
130
- var baseScope = scopes[0];
131
- if (scopes.length === 1) return baseScope;
132
- var createScope = function () {
133
- var scopeHooks = scopes.map(function (createScope2) {
134
- return {
135
- useScope: createScope2(),
136
- scopeName: createScope2.scopeName
137
- };
138
- });
139
- return function useComposedScopes(overrideScopes) {
140
- var nextScopes = scopeHooks.reduce(function (nextScopes2, param) {
141
- var {
142
- useScope,
143
- scopeName
144
- } = param;
145
- var scopeProps = useScope(overrideScopes);
146
- var currentScope = scopeProps[`__scope${scopeName}`];
147
- return {
148
- ...nextScopes2,
149
- ...currentScope
150
- };
151
- }, {});
152
- return React.useMemo(function () {
153
- return {
154
- [`__scope${baseScope.scopeName}`]: nextScopes
155
- };
156
- }, [nextScopes]);
157
- };
158
- };
159
- createScope.scopeName = baseScope.scopeName;
160
- return createScope;
111
+ for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
112
+ scopes[_key] = arguments[_key];
113
+ }
114
+ var baseScope = scopes[0];
115
+ if (scopes.length === 1) return baseScope;
116
+ var createScope = function() {
117
+ var scopeHooks = scopes.map(function(createScope2) {
118
+ return {
119
+ useScope: createScope2(),
120
+ scopeName: createScope2.scopeName
121
+ };
122
+ });
123
+ return function useComposedScopes(overrideScopes) {
124
+ var nextScopes = scopeHooks.reduce(function(nextScopes2, param) {
125
+ var { useScope, scopeName } = param;
126
+ var scopeProps = useScope(overrideScopes);
127
+ var currentScope = scopeProps[`__scope${scopeName}`];
128
+ return {
129
+ ...nextScopes2,
130
+ ...currentScope
131
+ };
132
+ }, {});
133
+ return React.useMemo(function() {
134
+ return { [`__scope${baseScope.scopeName}`]: nextScopes };
135
+ }, [nextScopes]);
136
+ };
137
+ };
138
+ createScope.scopeName = baseScope.scopeName;
139
+ return createScope;
161
140
  }
141
+
162
142
  //# sourceMappingURL=create-context.native.js.map