@tamagui/create-context 1.110.5 → 1.111.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.
- package/dist/cjs/create-context.native.js +24 -96
- package/dist/cjs/create-context.native.js.map +1 -1
- package/dist/esm/create-context.native.js +27 -99
- package/dist/esm/create-context.native.js.map +1 -1
- package/dist/esm/create-context.native.mjs +113 -0
- package/dist/esm/create-context.native.mjs.map +1 -0
- package/dist/esm/index.native.mjs +2 -0
- package/dist/esm/index.native.mjs.map +1 -0
- package/dist/jsx/create-context.native.js +24 -96
- package/dist/jsx/create-context.native.js.map +1 -1
- package/package.json +2 -2
|
@@ -28,88 +28,10 @@ __export(create_context_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(create_context_exports);
|
|
30
30
|
var import_jsx_runtime = require("react/jsx-runtime"), React = __toESM(require("react"));
|
|
31
|
-
function _array_like_to_array(arr, len) {
|
|
32
|
-
(len == null || len > arr.length) && (len = arr.length);
|
|
33
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
34
|
-
return arr2;
|
|
35
|
-
}
|
|
36
|
-
function _array_without_holes(arr) {
|
|
37
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
38
|
-
}
|
|
39
|
-
function _define_property(obj, key, value) {
|
|
40
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
41
|
-
value,
|
|
42
|
-
enumerable: !0,
|
|
43
|
-
configurable: !0,
|
|
44
|
-
writable: !0
|
|
45
|
-
}) : obj[key] = value, obj;
|
|
46
|
-
}
|
|
47
|
-
function _iterable_to_array(iter) {
|
|
48
|
-
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
49
|
-
}
|
|
50
|
-
function _non_iterable_spread() {
|
|
51
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
52
|
-
}
|
|
53
|
-
function _object_spread(target) {
|
|
54
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
55
|
-
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
56
|
-
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
57
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
58
|
-
}))), ownKeys2.forEach(function(key) {
|
|
59
|
-
_define_property(target, key, source[key]);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return target;
|
|
63
|
-
}
|
|
64
|
-
function ownKeys(object, enumerableOnly) {
|
|
65
|
-
var keys = Object.keys(object);
|
|
66
|
-
if (Object.getOwnPropertySymbols) {
|
|
67
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
68
|
-
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
69
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
70
|
-
})), keys.push.apply(keys, symbols);
|
|
71
|
-
}
|
|
72
|
-
return keys;
|
|
73
|
-
}
|
|
74
|
-
function _object_spread_props(target, source) {
|
|
75
|
-
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
76
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
77
|
-
}), target;
|
|
78
|
-
}
|
|
79
|
-
function _object_without_properties(source, excluded) {
|
|
80
|
-
if (source == null) return {};
|
|
81
|
-
var target = _object_without_properties_loose(source, excluded), key, i;
|
|
82
|
-
if (Object.getOwnPropertySymbols) {
|
|
83
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
84
|
-
for (i = 0; i < sourceSymbolKeys.length; i++)
|
|
85
|
-
key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
|
|
86
|
-
}
|
|
87
|
-
return target;
|
|
88
|
-
}
|
|
89
|
-
function _object_without_properties_loose(source, excluded) {
|
|
90
|
-
if (source == null) return {};
|
|
91
|
-
var target = {}, sourceKeys = Object.keys(source), key, i;
|
|
92
|
-
for (i = 0; i < sourceKeys.length; i++)
|
|
93
|
-
key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
|
|
94
|
-
return target;
|
|
95
|
-
}
|
|
96
|
-
function _to_consumable_array(arr) {
|
|
97
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
98
|
-
}
|
|
99
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
100
|
-
if (o) {
|
|
101
|
-
if (typeof o == "string") return _array_like_to_array(o, minLen);
|
|
102
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
103
|
-
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
|
|
104
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
31
|
function createContext(rootComponentName, defaultContext) {
|
|
108
32
|
var Context = /* @__PURE__ */ React.createContext(defaultContext);
|
|
109
33
|
function Provider(props) {
|
|
110
|
-
var children = props
|
|
111
|
-
"children"
|
|
112
|
-
]), value = React.useMemo(function() {
|
|
34
|
+
var { children, ...context } = props, value = React.useMemo(function() {
|
|
113
35
|
return context;
|
|
114
36
|
}, Object.values(context));
|
|
115
37
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
@@ -121,9 +43,9 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
121
43
|
var context = React.useContext(Context);
|
|
122
44
|
if (context) return context;
|
|
123
45
|
if (defaultContext !== void 0) return defaultContext;
|
|
124
|
-
throw new Error(
|
|
46
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
125
47
|
}
|
|
126
|
-
return Provider.displayName =
|
|
48
|
+
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
127
49
|
Provider,
|
|
128
50
|
useContext
|
|
129
51
|
];
|
|
@@ -132,14 +54,12 @@ function createContextScope(scopeName) {
|
|
|
132
54
|
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [], defaultContexts = [];
|
|
133
55
|
function createContext2(rootComponentName, defaultContext) {
|
|
134
56
|
var BaseContext = /* @__PURE__ */ React.createContext(defaultContext), index = defaultContexts.length;
|
|
135
|
-
defaultContexts =
|
|
57
|
+
defaultContexts = [
|
|
58
|
+
...defaultContexts,
|
|
136
59
|
defaultContext
|
|
137
|
-
]
|
|
60
|
+
];
|
|
138
61
|
function Provider(props) {
|
|
139
|
-
var _scope_scopeName,
|
|
140
|
-
"scope",
|
|
141
|
-
"children"
|
|
142
|
-
]), Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, value = React.useMemo(function() {
|
|
62
|
+
var _scope_scopeName, { scope, children, ...context } = props, Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, value = React.useMemo(function() {
|
|
143
63
|
return context;
|
|
144
64
|
}, Object.values(context));
|
|
145
65
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
@@ -151,12 +71,12 @@ function createContextScope(scopeName) {
|
|
|
151
71
|
var _scope_scopeName, Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, context = React.useContext(Context);
|
|
152
72
|
if (context) return context;
|
|
153
73
|
if (defaultContext !== void 0) return defaultContext;
|
|
154
|
-
var missingContextMessage =
|
|
74
|
+
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
155
75
|
if (options != null && options.fallback)
|
|
156
76
|
return (options == null ? void 0 : options.warn) !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
157
77
|
throw new Error(missingContextMessage);
|
|
158
78
|
}
|
|
159
|
-
return Provider.displayName =
|
|
79
|
+
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
160
80
|
Provider,
|
|
161
81
|
useContext
|
|
162
82
|
];
|
|
@@ -168,7 +88,12 @@ function createContextScope(scopeName) {
|
|
|
168
88
|
return function(scope) {
|
|
169
89
|
var contexts = (scope == null ? void 0 : scope[scopeName]) || scopeContexts;
|
|
170
90
|
return React.useMemo(function() {
|
|
171
|
-
return
|
|
91
|
+
return {
|
|
92
|
+
[`__scope${scopeName}`]: {
|
|
93
|
+
...scope,
|
|
94
|
+
[scopeName]: contexts
|
|
95
|
+
}
|
|
96
|
+
};
|
|
172
97
|
}, [
|
|
173
98
|
scope,
|
|
174
99
|
contexts
|
|
@@ -177,9 +102,7 @@ function createContextScope(scopeName) {
|
|
|
177
102
|
};
|
|
178
103
|
return createScope.scopeName = scopeName, [
|
|
179
104
|
createContext2,
|
|
180
|
-
composeContextScopes
|
|
181
|
-
createScope
|
|
182
|
-
].concat(_to_consumable_array(createContextScopeDeps)))
|
|
105
|
+
composeContextScopes(createScope, ...createContextScopeDeps)
|
|
183
106
|
];
|
|
184
107
|
}
|
|
185
108
|
function composeContextScopes() {
|
|
@@ -196,11 +119,16 @@ function composeContextScopes() {
|
|
|
196
119
|
});
|
|
197
120
|
return function(overrideScopes) {
|
|
198
121
|
var nextScopes = scopeHooks.reduce(function(nextScopes2, param) {
|
|
199
|
-
var
|
|
200
|
-
return
|
|
122
|
+
var { useScope, scopeName } = param, scopeProps = useScope(overrideScopes), currentScope = scopeProps[`__scope${scopeName}`];
|
|
123
|
+
return {
|
|
124
|
+
...nextScopes2,
|
|
125
|
+
...currentScope
|
|
126
|
+
};
|
|
201
127
|
}, {});
|
|
202
128
|
return React.useMemo(function() {
|
|
203
|
-
return
|
|
129
|
+
return {
|
|
130
|
+
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
131
|
+
};
|
|
204
132
|
}, [
|
|
205
133
|
nextScopes
|
|
206
134
|
]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/code/core/create-context/src/create-context.tsx"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;uDAGA,QAAuB
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;uDAGA,QAAuB;AAIhB,SAASA,cACdC,mBACAC,gBAAiC;AAEjC,MAAMC,UAAUC,sBAAMJ,cAA4CE,cAAAA;AAElE,WAASG,SAASC,OAAuD;AACvE,QAAM,EAAEC,UAAU,GAAGC,QAAAA,IAAYF,OAG3BG,QAAQL,MAAMM,QAAQ,WAAA;aAAMF;OAASG,OAAOC,OAAOJ,OAAAA,CAAAA;AACzD,WAAO,uCAAAK,KAACV,QAAQE,UAAQ;MAACI;;;EAC3B;AAEA,WAASK,WAAWC,cAAoB;AACtC,QAAMP,UAAUJ,MAAMU,WAAWX,OAAAA;AACjC,QAAIK,QAAS,QAAOA;AACpB,QAAIN,mBAAmBc,OAAW,QAAOd;AAEzC,UAAM,IAAIe,MAAM,KAAKF,YAAAA,4BAAwCd,iBAAAA,IAAqB;EACpF;AAEAI,kBAASa,cAAc,GAAGjB,iBAAAA,YACnB;IAACI;IAAUS;;AACpB;AAeO,SAASK,mBACdC,WAAiB;MACjBC,yBAAAA,UAAAA,SAAAA,KAAAA,UAAAA,CAAAA,MAAAA,SAAAA,UAAAA,CAAAA,IAAwC,CAAA,GAEpCC,kBAAyB,CAAA;AAM7B,WAAStB,eACPC,mBACAC,gBAAiC;AAEjC,QAAMqB,cAAcnB,sBAAMJ,cAA4CE,cAAAA,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EAAW,GAAG;YAAE,GAAGM;YAAO,CAACN,SAAAA,GAAYe;UAAS;QAAE;SACtE;QAACT;QAAOS;OAAS;IAErB;EACF;AAEAH,qBAAYZ,YAAYA,WACjB;IACLpB;IACAoC,qBAAqBJ,aAAAA,GAAgBX,sBAAAA;;AAEzC;AAMA,SAASe,uBAAAA;AAAqB,WAAA,OAAA,UAAA,QAAGC,SAAH,IAAA,MAAA,IAAA,GAAA,OAAA,GAAA,OAAA,MAAA;AAAGA,WAAH,IAAA,IAAA,UAAA,IAAA;AAC5B,MAAMC,YAAYD,OAAO,CAAA;AACzB,MAAIA,OAAOZ,WAAW,EAAG,QAAOa;AAEhC,MAAMN,cAA2B,WAAA;AAC/B,QAAMO,aAAaF,OAAOH,IAAI,SAACF,cAAAA;aAAiB;QAC9CQ,UAAUR,aAAAA;QACVZ,WAAWY,aAAYZ;MACzB;;AAEA,WAAO,SAA2BqB,gBAAc;AAC9C,UAAMC,aAAaH,WAAWI,OAAO,SAACD,aAAAA,OAAAA;YAAY,EAAEF,UAAUpB,UAAS,IAAE,OAIjEwB,aAAaJ,SAASC,cAAAA,GACtBI,eAAeD,WAAW,UAAUxB,SAAAA,EAAW;AACrD,eAAO;UAAE,GAAGsB;UAAY,GAAGG;QAAa;MAC1C,GAAG,CAAC,CAAA;AAEJ,aAAOzC,MAAMM,QACX,WAAA;eAAO;UAAE,CAAC,UAAU4B,UAAUlB,SAAS,EAAE,GAAGsB;QAAW;SACvD;QAACA;OAAW;IAEhB;EACF;AAEAV,qBAAYZ,YAAYkB,UAAUlB,WAC3BY;AACT;",
|
|
5
5
|
"names": ["createContext", "rootComponentName", "defaultContext", "Context", "React", "Provider", "props", "children", "context", "value", "useMemo", "Object", "values", "_jsx", "useContext", "consumerName", "undefined", "Error", "displayName", "createContextScope", "scopeName", "createContextScopeDeps", "defaultContexts", "BaseContext", "index", "length", "scope", "options", "missingContextMessage", "fallback", "warn", "console", "createScope", "scopeContexts", "map", "contexts", "composeContextScopes", "scopes", "baseScope", "scopeHooks", "useScope", "overrideScopes", "nextScopes", "reduce", "scopeProps", "currentScope"]
|
|
6
6
|
}
|
|
@@ -1,87 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
function _array_like_to_array(arr, len) {
|
|
4
|
-
(len == null || len > arr.length) && (len = arr.length);
|
|
5
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
6
|
-
return arr2;
|
|
7
|
-
}
|
|
8
|
-
function _array_without_holes(arr) {
|
|
9
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
10
|
-
}
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
13
|
-
value,
|
|
14
|
-
enumerable: !0,
|
|
15
|
-
configurable: !0,
|
|
16
|
-
writable: !0
|
|
17
|
-
}) : obj[key] = value, obj;
|
|
18
|
-
}
|
|
19
|
-
function _iterable_to_array(iter) {
|
|
20
|
-
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
21
|
-
}
|
|
22
|
-
function _non_iterable_spread() {
|
|
23
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
24
|
-
}
|
|
25
|
-
function _object_spread(target) {
|
|
26
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
-
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
28
|
-
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
29
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
30
|
-
}))), ownKeys2.forEach(function(key) {
|
|
31
|
-
_define_property(target, key, source[key]);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
}
|
|
36
|
-
function ownKeys(object, enumerableOnly) {
|
|
37
|
-
var keys = Object.keys(object);
|
|
38
|
-
if (Object.getOwnPropertySymbols) {
|
|
39
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
40
|
-
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
41
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
42
|
-
})), keys.push.apply(keys, symbols);
|
|
43
|
-
}
|
|
44
|
-
return keys;
|
|
45
|
-
}
|
|
46
|
-
function _object_spread_props(target, source) {
|
|
47
|
-
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
-
}), target;
|
|
50
|
-
}
|
|
51
|
-
function _object_without_properties(source, excluded) {
|
|
52
|
-
if (source == null) return {};
|
|
53
|
-
var target = _object_without_properties_loose(source, excluded), key, i;
|
|
54
|
-
if (Object.getOwnPropertySymbols) {
|
|
55
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
56
|
-
for (i = 0; i < sourceSymbolKeys.length; i++)
|
|
57
|
-
key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
|
|
58
|
-
}
|
|
59
|
-
return target;
|
|
60
|
-
}
|
|
61
|
-
function _object_without_properties_loose(source, excluded) {
|
|
62
|
-
if (source == null) return {};
|
|
63
|
-
var target = {}, sourceKeys = Object.keys(source), key, i;
|
|
64
|
-
for (i = 0; i < sourceKeys.length; i++)
|
|
65
|
-
key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
|
|
66
|
-
return target;
|
|
67
|
-
}
|
|
68
|
-
function _to_consumable_array(arr) {
|
|
69
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
70
|
-
}
|
|
71
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
72
|
-
if (o) {
|
|
73
|
-
if (typeof o == "string") return _array_like_to_array(o, minLen);
|
|
74
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
75
|
-
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
|
|
76
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
3
|
function createContext(rootComponentName, defaultContext) {
|
|
80
4
|
var Context = /* @__PURE__ */ React.createContext(defaultContext);
|
|
81
5
|
function Provider(props) {
|
|
82
|
-
var children = props
|
|
83
|
-
"children"
|
|
84
|
-
]), value = React.useMemo(function() {
|
|
6
|
+
var { children, ...context } = props, value = React.useMemo(function() {
|
|
85
7
|
return context;
|
|
86
8
|
}, Object.values(context));
|
|
87
9
|
return /* @__PURE__ */ _jsx(Context.Provider, {
|
|
@@ -93,9 +15,9 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
93
15
|
var context = React.useContext(Context);
|
|
94
16
|
if (context) return context;
|
|
95
17
|
if (defaultContext !== void 0) return defaultContext;
|
|
96
|
-
throw new Error(
|
|
18
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
97
19
|
}
|
|
98
|
-
return Provider.displayName =
|
|
20
|
+
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
99
21
|
Provider,
|
|
100
22
|
useContext
|
|
101
23
|
];
|
|
@@ -104,14 +26,12 @@ function createContextScope(scopeName) {
|
|
|
104
26
|
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [], defaultContexts = [];
|
|
105
27
|
function createContext2(rootComponentName, defaultContext) {
|
|
106
28
|
var BaseContext = /* @__PURE__ */ React.createContext(defaultContext), index = defaultContexts.length;
|
|
107
|
-
defaultContexts =
|
|
29
|
+
defaultContexts = [
|
|
30
|
+
...defaultContexts,
|
|
108
31
|
defaultContext
|
|
109
|
-
]
|
|
32
|
+
];
|
|
110
33
|
function Provider(props) {
|
|
111
|
-
var _scope_scopeName,
|
|
112
|
-
"scope",
|
|
113
|
-
"children"
|
|
114
|
-
]), Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, value = React.useMemo(function() {
|
|
34
|
+
var _scope_scopeName, { scope, children, ...context } = props, Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, value = React.useMemo(function() {
|
|
115
35
|
return context;
|
|
116
36
|
}, Object.values(context));
|
|
117
37
|
return /* @__PURE__ */ _jsx(Context.Provider, {
|
|
@@ -123,12 +43,12 @@ function createContextScope(scopeName) {
|
|
|
123
43
|
var _scope_scopeName, Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, context = React.useContext(Context);
|
|
124
44
|
if (context) return context;
|
|
125
45
|
if (defaultContext !== void 0) return defaultContext;
|
|
126
|
-
var missingContextMessage =
|
|
127
|
-
if (options
|
|
128
|
-
return
|
|
46
|
+
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
47
|
+
if (options?.fallback)
|
|
48
|
+
return options?.warn !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
129
49
|
throw new Error(missingContextMessage);
|
|
130
50
|
}
|
|
131
|
-
return Provider.displayName =
|
|
51
|
+
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
132
52
|
Provider,
|
|
133
53
|
useContext
|
|
134
54
|
];
|
|
@@ -138,9 +58,14 @@ function createContextScope(scopeName) {
|
|
|
138
58
|
return /* @__PURE__ */ React.createContext(defaultContext);
|
|
139
59
|
});
|
|
140
60
|
return function(scope) {
|
|
141
|
-
var contexts =
|
|
61
|
+
var contexts = scope?.[scopeName] || scopeContexts;
|
|
142
62
|
return React.useMemo(function() {
|
|
143
|
-
return
|
|
63
|
+
return {
|
|
64
|
+
[`__scope${scopeName}`]: {
|
|
65
|
+
...scope,
|
|
66
|
+
[scopeName]: contexts
|
|
67
|
+
}
|
|
68
|
+
};
|
|
144
69
|
}, [
|
|
145
70
|
scope,
|
|
146
71
|
contexts
|
|
@@ -149,9 +74,7 @@ function createContextScope(scopeName) {
|
|
|
149
74
|
};
|
|
150
75
|
return createScope.scopeName = scopeName, [
|
|
151
76
|
createContext2,
|
|
152
|
-
composeContextScopes
|
|
153
|
-
createScope
|
|
154
|
-
].concat(_to_consumable_array(createContextScopeDeps)))
|
|
77
|
+
composeContextScopes(createScope, ...createContextScopeDeps)
|
|
155
78
|
];
|
|
156
79
|
}
|
|
157
80
|
function composeContextScopes() {
|
|
@@ -168,11 +91,16 @@ function composeContextScopes() {
|
|
|
168
91
|
});
|
|
169
92
|
return function(overrideScopes) {
|
|
170
93
|
var nextScopes = scopeHooks.reduce(function(nextScopes2, param) {
|
|
171
|
-
var
|
|
172
|
-
return
|
|
94
|
+
var { useScope, scopeName } = param, scopeProps = useScope(overrideScopes), currentScope = scopeProps[`__scope${scopeName}`];
|
|
95
|
+
return {
|
|
96
|
+
...nextScopes2,
|
|
97
|
+
...currentScope
|
|
98
|
+
};
|
|
173
99
|
}, {});
|
|
174
100
|
return React.useMemo(function() {
|
|
175
|
-
return
|
|
101
|
+
return {
|
|
102
|
+
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
103
|
+
};
|
|
176
104
|
}, [
|
|
177
105
|
nextScopes
|
|
178
106
|
]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/code/core/create-context/src/create-context.tsx"],
|
|
4
|
-
"mappings": ";AAGA,YAAYA,WAAW
|
|
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iB;QAC9CQ,UAAUR,aAAAA;QACVZ,WAAWY,aAAYZ;MACzB;;AAEA,WAAO,SAA2BqB,gBAAc;AAC9C,UAAMC,aAAaH,WAAWI,OAAO,SAACD,aAAAA,OAAAA;YAAY,EAAEF,UAAUpB,UAAS,IAAE,OAIjEwB,aAAaJ,SAASC,cAAAA,GACtBI,eAAeD,WAAW,UAAUxB,SAAAA,EAAW;AACrD,eAAO;UAAE,GAAGsB;UAAY,GAAGG;QAAa;MAC1C,GAAG,CAAC,CAAA;AAEJ,aAAO5C,MAAMU,QACX,WAAA;eAAO;UAAE,CAAC,UAAU2B,UAAUlB,SAAS,EAAE,GAAGsB;QAAW;SACvD;QAACA;OAAW;IAEhB;EACF;AAEAV,qBAAYZ,YAAYkB,UAAUlB,WAC3BY;AACT;",
|
|
5
5
|
"names": ["React", "createContext", "rootComponentName", "defaultContext", "Context", "Provider", "props", "children", "context", "value", "useMemo", "Object", "values", "useContext", "consumerName", "undefined", "Error", "displayName", "createContextScope", "scopeName", "createContextScopeDeps", "defaultContexts", "BaseContext", "index", "length", "scope", "options", "missingContextMessage", "fallback", "warn", "console", "createScope", "scopeContexts", "map", "contexts", "composeContextScopes", "scopes", "baseScope", "scopeHooks", "useScope", "overrideScopes", "nextScopes", "reduce", "scopeProps", "currentScope"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
function createContext(rootComponentName, defaultContext) {
|
|
4
|
+
var Context = /* @__PURE__ */React.createContext(defaultContext);
|
|
5
|
+
function Provider(props) {
|
|
6
|
+
var {
|
|
7
|
+
children,
|
|
8
|
+
...context
|
|
9
|
+
} = props,
|
|
10
|
+
value = React.useMemo(function () {
|
|
11
|
+
return context;
|
|
12
|
+
}, Object.values(context));
|
|
13
|
+
return /* @__PURE__ */_jsx(Context.Provider, {
|
|
14
|
+
value,
|
|
15
|
+
children
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function useContext(consumerName) {
|
|
19
|
+
var context = React.useContext(Context);
|
|
20
|
+
if (context) return context;
|
|
21
|
+
if (defaultContext !== void 0) return defaultContext;
|
|
22
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
23
|
+
}
|
|
24
|
+
return Provider.displayName = `${rootComponentName}Provider`, [Provider, useContext];
|
|
25
|
+
}
|
|
26
|
+
function createContextScope(scopeName) {
|
|
27
|
+
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [],
|
|
28
|
+
defaultContexts = [];
|
|
29
|
+
function createContext2(rootComponentName, defaultContext) {
|
|
30
|
+
var BaseContext = /* @__PURE__ */React.createContext(defaultContext),
|
|
31
|
+
index = defaultContexts.length;
|
|
32
|
+
defaultContexts = [...defaultContexts, defaultContext];
|
|
33
|
+
function Provider(props) {
|
|
34
|
+
var _scope_scopeName,
|
|
35
|
+
{
|
|
36
|
+
scope,
|
|
37
|
+
children,
|
|
38
|
+
...context
|
|
39
|
+
} = props,
|
|
40
|
+
Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext,
|
|
41
|
+
value = React.useMemo(function () {
|
|
42
|
+
return context;
|
|
43
|
+
}, Object.values(context));
|
|
44
|
+
return /* @__PURE__ */_jsx(Context.Provider, {
|
|
45
|
+
value,
|
|
46
|
+
children
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function useContext(consumerName, scope, options) {
|
|
50
|
+
var _scope_scopeName,
|
|
51
|
+
Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext,
|
|
52
|
+
context = React.useContext(Context);
|
|
53
|
+
if (context) return context;
|
|
54
|
+
if (defaultContext !== void 0) return defaultContext;
|
|
55
|
+
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
56
|
+
if (options?.fallback) return options?.warn !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
57
|
+
throw new Error(missingContextMessage);
|
|
58
|
+
}
|
|
59
|
+
return Provider.displayName = `${rootComponentName}Provider`, [Provider, useContext];
|
|
60
|
+
}
|
|
61
|
+
var createScope = function () {
|
|
62
|
+
var scopeContexts = defaultContexts.map(function (defaultContext) {
|
|
63
|
+
return /* @__PURE__ */React.createContext(defaultContext);
|
|
64
|
+
});
|
|
65
|
+
return function (scope) {
|
|
66
|
+
var contexts = scope?.[scopeName] || scopeContexts;
|
|
67
|
+
return React.useMemo(function () {
|
|
68
|
+
return {
|
|
69
|
+
[`__scope${scopeName}`]: {
|
|
70
|
+
...scope,
|
|
71
|
+
[scopeName]: contexts
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}, [scope, contexts]);
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
return createScope.scopeName = scopeName, [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
78
|
+
}
|
|
79
|
+
function composeContextScopes() {
|
|
80
|
+
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) scopes[_key] = arguments[_key];
|
|
81
|
+
var baseScope = scopes[0];
|
|
82
|
+
if (scopes.length === 1) return baseScope;
|
|
83
|
+
var createScope = function () {
|
|
84
|
+
var scopeHooks = scopes.map(function (createScope2) {
|
|
85
|
+
return {
|
|
86
|
+
useScope: createScope2(),
|
|
87
|
+
scopeName: createScope2.scopeName
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
return function (overrideScopes) {
|
|
91
|
+
var nextScopes = scopeHooks.reduce(function (nextScopes2, param) {
|
|
92
|
+
var {
|
|
93
|
+
useScope,
|
|
94
|
+
scopeName
|
|
95
|
+
} = param,
|
|
96
|
+
scopeProps = useScope(overrideScopes),
|
|
97
|
+
currentScope = scopeProps[`__scope${scopeName}`];
|
|
98
|
+
return {
|
|
99
|
+
...nextScopes2,
|
|
100
|
+
...currentScope
|
|
101
|
+
};
|
|
102
|
+
}, {});
|
|
103
|
+
return React.useMemo(function () {
|
|
104
|
+
return {
|
|
105
|
+
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
106
|
+
};
|
|
107
|
+
}, [nextScopes]);
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
return createScope.scopeName = baseScope.scopeName, createScope;
|
|
111
|
+
}
|
|
112
|
+
export { createContext, createContextScope };
|
|
113
|
+
//# sourceMappingURL=create-context.native.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","React","createContext","rootComponentName","defaultContext","Context","Provider","props","children","context","value","useMemo","Object","values","useContext","consumerName","Error","displayName","createContextScope","scopeName","createContextScopeDeps","arguments","length","defaultContexts","createContext2","BaseContext","index","_scope_scopeName","scope","options","missingContextMessage","fallback","warn","console","createScope","scopeContexts","map","contexts"],"sources":["../../src/create-context.tsx"],"sourcesContent":[null],"mappings":"AAGA,SAAAA,GAAY,IAAAC,IAAA,QAAW;AAeZ,YAAAC,KAAA;AAXJ,SAASC,cACdC,iBAAA,EACAC,cAAA,EACA;EACA,IAAAC,OAAM,kBAAgBJ,KAAA,CAA4CC,aAAA,CAAcE,cAAA;EAEhF,SAASE,SAASC,KAAA,EAAyD;IACzE;QAAMC,QAAE;QAAA,GAAUC;MAAG,IAAQF,KAAI;MAAAG,KAG3B,GAAAT,KAAQ,CAAAU,OAAM,aAAc;QAClC,OAAOF,OAAA;MACT,GAAAG,MAAA,CAAAC,MAAA,CAAAJ,OAAA;IAEA,OAAS,eAAWT,IAAA,CAAAK,OAA0D,CAAAC,QAAA;MAC5EI,KAAM;MACNF;IACA;EAEA;EACF,SAAAM,WAAAC,YAAA;IAEA,IAAAN,OAAA,GAASR,KAAA,CAAAa,UAAc,CAAGT,OAAA;IAE5B,IAAAI,OAAA,SAAAA,OAAA;IAeO,IAAAL,cAAS,UACd,UACAA,cAAA;IAEA,MAAI,IAAAY,KAAA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AU,QAAS,OAAOA,cAAW;MAAuB,IACrE0B,qBAAe,QAAAf,YAAA,4BAAAZ,iBAAA;MAClB,IAAA0B,OAAA,EAAAE,QAAA,EACF,OAAAF,OAAA,EAAAG,IAAA,WAAAC,OAAA,CAAAD,IAAA,CAAAF,qBAAA,GAAAD,OAAA,CAAAE,QAAA;MACF,UAAAf,KAAA,CAAAc,qBAAA;IAEA;IAEE,OAAAxB,QAAA,CAAAW,WAAA,MAAAd,iBAAA,aACAG,QAAA,EACFQ,UAAA,CACF;EAMA;EACE,IAAAoB,WAAM,GAAY,SAAAA,CAAA,EAAQ;IAC1B,IAAIC,aAAO,GAAWZ,eAAU,CAAAa,GAAA,WAAAhC,cAAA;MAEhC,OAAM,eAAiCH,KAAA,CAAAC,aAAA,CAAAE,cAAA;IACrC;IAAgD,OAC9C,UAAUwB,KAAA;MACV,IAAAS,QAAW,GAAAT,KAAA,GAAAT,SAAY,KAAAgB,aAAA;MACvB,OAAAlC,KAAA,CAAAU,OAAA;QAEF,OAAO;UACL,WAAMQ,SAAa;YAKjB,GAAMS,KAAA;YACN,CAAAT,SAAY,GAAAkB;UACV;QAEJ;MAAa,GACX,CACAT,KAAC,EACHS,QAAA,CACF;IACF;EAEA;EAEF,OAAAH,WAAA,CAAAf,SAAA,GAAAA,SAAA,G","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -1,87 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
function _array_like_to_array(arr, len) {
|
|
4
|
-
(len == null || len > arr.length) && (len = arr.length);
|
|
5
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
6
|
-
return arr2;
|
|
7
|
-
}
|
|
8
|
-
function _array_without_holes(arr) {
|
|
9
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
10
|
-
}
|
|
11
|
-
function _define_property(obj, key, value) {
|
|
12
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
13
|
-
value,
|
|
14
|
-
enumerable: !0,
|
|
15
|
-
configurable: !0,
|
|
16
|
-
writable: !0
|
|
17
|
-
}) : obj[key] = value, obj;
|
|
18
|
-
}
|
|
19
|
-
function _iterable_to_array(iter) {
|
|
20
|
-
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
21
|
-
}
|
|
22
|
-
function _non_iterable_spread() {
|
|
23
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
24
|
-
}
|
|
25
|
-
function _object_spread(target) {
|
|
26
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
27
|
-
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
28
|
-
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
29
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
30
|
-
}))), ownKeys2.forEach(function(key) {
|
|
31
|
-
_define_property(target, key, source[key]);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
}
|
|
36
|
-
function ownKeys(object, enumerableOnly) {
|
|
37
|
-
var keys = Object.keys(object);
|
|
38
|
-
if (Object.getOwnPropertySymbols) {
|
|
39
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
40
|
-
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
41
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
42
|
-
})), keys.push.apply(keys, symbols);
|
|
43
|
-
}
|
|
44
|
-
return keys;
|
|
45
|
-
}
|
|
46
|
-
function _object_spread_props(target, source) {
|
|
47
|
-
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
-
}), target;
|
|
50
|
-
}
|
|
51
|
-
function _object_without_properties(source, excluded) {
|
|
52
|
-
if (source == null) return {};
|
|
53
|
-
var target = _object_without_properties_loose(source, excluded), key, i;
|
|
54
|
-
if (Object.getOwnPropertySymbols) {
|
|
55
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
56
|
-
for (i = 0; i < sourceSymbolKeys.length; i++)
|
|
57
|
-
key = sourceSymbolKeys[i], !(excluded.indexOf(key) >= 0) && Object.prototype.propertyIsEnumerable.call(source, key) && (target[key] = source[key]);
|
|
58
|
-
}
|
|
59
|
-
return target;
|
|
60
|
-
}
|
|
61
|
-
function _object_without_properties_loose(source, excluded) {
|
|
62
|
-
if (source == null) return {};
|
|
63
|
-
var target = {}, sourceKeys = Object.keys(source), key, i;
|
|
64
|
-
for (i = 0; i < sourceKeys.length; i++)
|
|
65
|
-
key = sourceKeys[i], !(excluded.indexOf(key) >= 0) && (target[key] = source[key]);
|
|
66
|
-
return target;
|
|
67
|
-
}
|
|
68
|
-
function _to_consumable_array(arr) {
|
|
69
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
70
|
-
}
|
|
71
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
72
|
-
if (o) {
|
|
73
|
-
if (typeof o == "string") return _array_like_to_array(o, minLen);
|
|
74
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
75
|
-
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
|
|
76
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
3
|
function createContext(rootComponentName, defaultContext) {
|
|
80
4
|
var Context = /* @__PURE__ */ React.createContext(defaultContext);
|
|
81
5
|
function Provider(props) {
|
|
82
|
-
var children = props
|
|
83
|
-
"children"
|
|
84
|
-
]), value = React.useMemo(function() {
|
|
6
|
+
var { children, ...context } = props, value = React.useMemo(function() {
|
|
85
7
|
return context;
|
|
86
8
|
}, Object.values(context));
|
|
87
9
|
return /* @__PURE__ */ _jsx(Context.Provider, {
|
|
@@ -93,9 +15,9 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
93
15
|
var context = React.useContext(Context);
|
|
94
16
|
if (context) return context;
|
|
95
17
|
if (defaultContext !== void 0) return defaultContext;
|
|
96
|
-
throw new Error(
|
|
18
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
97
19
|
}
|
|
98
|
-
return Provider.displayName =
|
|
20
|
+
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
99
21
|
Provider,
|
|
100
22
|
useContext
|
|
101
23
|
];
|
|
@@ -104,14 +26,12 @@ function createContextScope(scopeName) {
|
|
|
104
26
|
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [], defaultContexts = [];
|
|
105
27
|
function createContext2(rootComponentName, defaultContext) {
|
|
106
28
|
var BaseContext = /* @__PURE__ */ React.createContext(defaultContext), index = defaultContexts.length;
|
|
107
|
-
defaultContexts =
|
|
29
|
+
defaultContexts = [
|
|
30
|
+
...defaultContexts,
|
|
108
31
|
defaultContext
|
|
109
|
-
]
|
|
32
|
+
];
|
|
110
33
|
function Provider(props) {
|
|
111
|
-
var _scope_scopeName,
|
|
112
|
-
"scope",
|
|
113
|
-
"children"
|
|
114
|
-
]), Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, value = React.useMemo(function() {
|
|
34
|
+
var _scope_scopeName, { scope, children, ...context } = props, Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, value = React.useMemo(function() {
|
|
115
35
|
return context;
|
|
116
36
|
}, Object.values(context));
|
|
117
37
|
return /* @__PURE__ */ _jsx(Context.Provider, {
|
|
@@ -123,12 +43,12 @@ function createContextScope(scopeName) {
|
|
|
123
43
|
var _scope_scopeName, Context = (scope == null || (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext, context = React.useContext(Context);
|
|
124
44
|
if (context) return context;
|
|
125
45
|
if (defaultContext !== void 0) return defaultContext;
|
|
126
|
-
var missingContextMessage =
|
|
46
|
+
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
127
47
|
if (options != null && options.fallback)
|
|
128
48
|
return (options == null ? void 0 : options.warn) !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
129
49
|
throw new Error(missingContextMessage);
|
|
130
50
|
}
|
|
131
|
-
return Provider.displayName =
|
|
51
|
+
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
132
52
|
Provider,
|
|
133
53
|
useContext
|
|
134
54
|
];
|
|
@@ -140,7 +60,12 @@ function createContextScope(scopeName) {
|
|
|
140
60
|
return function(scope) {
|
|
141
61
|
var contexts = (scope == null ? void 0 : scope[scopeName]) || scopeContexts;
|
|
142
62
|
return React.useMemo(function() {
|
|
143
|
-
return
|
|
63
|
+
return {
|
|
64
|
+
[`__scope${scopeName}`]: {
|
|
65
|
+
...scope,
|
|
66
|
+
[scopeName]: contexts
|
|
67
|
+
}
|
|
68
|
+
};
|
|
144
69
|
}, [
|
|
145
70
|
scope,
|
|
146
71
|
contexts
|
|
@@ -149,9 +74,7 @@ function createContextScope(scopeName) {
|
|
|
149
74
|
};
|
|
150
75
|
return createScope.scopeName = scopeName, [
|
|
151
76
|
createContext2,
|
|
152
|
-
composeContextScopes
|
|
153
|
-
createScope
|
|
154
|
-
].concat(_to_consumable_array(createContextScopeDeps)))
|
|
77
|
+
composeContextScopes(createScope, ...createContextScopeDeps)
|
|
155
78
|
];
|
|
156
79
|
}
|
|
157
80
|
function composeContextScopes() {
|
|
@@ -168,11 +91,16 @@ function composeContextScopes() {
|
|
|
168
91
|
});
|
|
169
92
|
return function(overrideScopes) {
|
|
170
93
|
var nextScopes = scopeHooks.reduce(function(nextScopes2, param) {
|
|
171
|
-
var
|
|
172
|
-
return
|
|
94
|
+
var { useScope, scopeName } = param, scopeProps = useScope(overrideScopes), currentScope = scopeProps[`__scope${scopeName}`];
|
|
95
|
+
return {
|
|
96
|
+
...nextScopes2,
|
|
97
|
+
...currentScope
|
|
98
|
+
};
|
|
173
99
|
}, {});
|
|
174
100
|
return React.useMemo(function() {
|
|
175
|
-
return
|
|
101
|
+
return {
|
|
102
|
+
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
103
|
+
};
|
|
176
104
|
}, [
|
|
177
105
|
nextScopes
|
|
178
106
|
]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/code/core/create-context/src/create-context.tsx"],
|
|
4
|
-
"mappings": ";AAGA,YAAYA,WAAW
|
|
4
|
+
"mappings": ";AAGA,YAAYA,WAAW;AAIhB,SAASC,cACdC,mBACAC,gBAAiC;AAEjC,MAAMC,UAAUJ,sBAAMC,cAA4CE,cAAAA;AAElE,WAASE,SAASC,OAAuD;AACvE,QAAM,EAAEC,UAAU,GAAGC,QAAAA,IAAYF,OAG3BG,QAAQT,MAAMU,QAAQ,WAAA;aAAMF;OAASG,OAAOC,OAAOJ,OAAAA,CAAAA;AACzD,WAAO,qBAACJ,QAAQC,UAAQ;MAACI;;;EAC3B;AAEA,WAASI,WAAWC,cAAoB;AACtC,QAAMN,UAAUR,MAAMa,WAAWT,OAAAA;AACjC,QAAII,QAAS,QAAOA;AACpB,QAAIL,mBAAmBY,OAAW,QAAOZ;AAEzC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AE,GAAGsB;QAAW;SACvD;QAACA;OAAW;IAEhB;EACF;AAEAV,qBAAYZ,YAAYkB,UAAUlB,WAC3BY;AACT;",
|
|
5
5
|
"names": ["React", "createContext", "rootComponentName", "defaultContext", "Context", "Provider", "props", "children", "context", "value", "useMemo", "Object", "values", "useContext", "consumerName", "undefined", "Error", "displayName", "createContextScope", "scopeName", "createContextScopeDeps", "defaultContexts", "BaseContext", "index", "length", "scope", "options", "missingContextMessage", "fallback", "warn", "console", "createScope", "scopeContexts", "map", "contexts", "composeContextScopes", "scopes", "baseScope", "scopeHooks", "useScope", "overrideScopes", "nextScopes", "reduce", "scopeProps", "currentScope"]
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-context",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.111.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tamagui/build": "1.
|
|
34
|
+
"@tamagui/build": "1.111.1",
|
|
35
35
|
"react": "^18.2.0 || ^19.0.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|