@tamagui/create-context 1.111.8 → 1.111.10
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/esm/create-context.native.js +53 -55
- package/dist/esm/create-context.native.js.map +1 -6
- package/dist/esm/index.native.js +2 -2
- package/dist/esm/index.native.js.map +1 -6
- package/package.json +3 -3
- package/dist/esm/create-context.native.mjs +0 -113
- package/dist/esm/create-context.native.mjs.map +0 -1
- package/dist/esm/index.native.mjs +0 -2
- package/dist/esm/index.native.mjs.map +0 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
function createContext(rootComponentName, defaultContext) {
|
|
4
|
-
var Context = /* @__PURE__ */
|
|
4
|
+
var Context = /* @__PURE__ */React.createContext(defaultContext);
|
|
5
5
|
function Provider(props) {
|
|
6
|
-
var {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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, {
|
|
10
14
|
value,
|
|
11
15
|
children
|
|
12
16
|
});
|
|
@@ -17,99 +21,93 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
17
21
|
if (defaultContext !== void 0) return defaultContext;
|
|
18
22
|
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
19
23
|
}
|
|
20
|
-
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
21
|
-
Provider,
|
|
22
|
-
useContext
|
|
23
|
-
];
|
|
24
|
+
return Provider.displayName = `${rootComponentName}Provider`, [Provider, useContext];
|
|
24
25
|
}
|
|
25
26
|
function createContextScope(scopeName) {
|
|
26
|
-
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [],
|
|
27
|
+
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [],
|
|
28
|
+
defaultContexts = [];
|
|
27
29
|
function createContext2(rootComponentName, defaultContext) {
|
|
28
|
-
var BaseContext = /* @__PURE__ */
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
defaultContext
|
|
32
|
-
];
|
|
30
|
+
var BaseContext = /* @__PURE__ */React.createContext(defaultContext),
|
|
31
|
+
index = defaultContexts.length;
|
|
32
|
+
defaultContexts = [...defaultContexts, defaultContext];
|
|
33
33
|
function Provider(props) {
|
|
34
|
-
var _scope_scopeName,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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, {
|
|
38
45
|
value,
|
|
39
46
|
children
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
49
|
function useContext(consumerName, scope, options) {
|
|
43
|
-
var _scope_scopeName,
|
|
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);
|
|
44
53
|
if (context) return context;
|
|
45
54
|
if (defaultContext !== void 0) return defaultContext;
|
|
46
55
|
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
47
|
-
if (options?.fallback)
|
|
48
|
-
return options?.warn !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
56
|
+
if (options?.fallback) return options?.warn !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
49
57
|
throw new Error(missingContextMessage);
|
|
50
58
|
}
|
|
51
|
-
return Provider.displayName = `${rootComponentName}Provider`, [
|
|
52
|
-
Provider,
|
|
53
|
-
useContext
|
|
54
|
-
];
|
|
59
|
+
return Provider.displayName = `${rootComponentName}Provider`, [Provider, useContext];
|
|
55
60
|
}
|
|
56
|
-
var createScope = function() {
|
|
57
|
-
var scopeContexts = defaultContexts.map(function(defaultContext) {
|
|
58
|
-
return /* @__PURE__ */
|
|
61
|
+
var createScope = function () {
|
|
62
|
+
var scopeContexts = defaultContexts.map(function (defaultContext) {
|
|
63
|
+
return /* @__PURE__ */React.createContext(defaultContext);
|
|
59
64
|
});
|
|
60
|
-
return function(scope) {
|
|
65
|
+
return function (scope) {
|
|
61
66
|
var contexts = scope?.[scopeName] || scopeContexts;
|
|
62
|
-
return React.useMemo(function() {
|
|
67
|
+
return React.useMemo(function () {
|
|
63
68
|
return {
|
|
64
69
|
[`__scope${scopeName}`]: {
|
|
65
70
|
...scope,
|
|
66
71
|
[scopeName]: contexts
|
|
67
72
|
}
|
|
68
73
|
};
|
|
69
|
-
}, [
|
|
70
|
-
scope,
|
|
71
|
-
contexts
|
|
72
|
-
]);
|
|
74
|
+
}, [scope, contexts]);
|
|
73
75
|
};
|
|
74
76
|
};
|
|
75
|
-
return createScope.scopeName = scopeName, [
|
|
76
|
-
createContext2,
|
|
77
|
-
composeContextScopes(createScope, ...createContextScopeDeps)
|
|
78
|
-
];
|
|
77
|
+
return createScope.scopeName = scopeName, [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
79
78
|
}
|
|
80
79
|
function composeContextScopes() {
|
|
81
|
-
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++)
|
|
82
|
-
scopes[_key] = arguments[_key];
|
|
80
|
+
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) scopes[_key] = arguments[_key];
|
|
83
81
|
var baseScope = scopes[0];
|
|
84
82
|
if (scopes.length === 1) return baseScope;
|
|
85
|
-
var createScope = function() {
|
|
86
|
-
var scopeHooks = scopes.map(function(createScope2) {
|
|
83
|
+
var createScope = function () {
|
|
84
|
+
var scopeHooks = scopes.map(function (createScope2) {
|
|
87
85
|
return {
|
|
88
86
|
useScope: createScope2(),
|
|
89
87
|
scopeName: createScope2.scopeName
|
|
90
88
|
};
|
|
91
89
|
});
|
|
92
|
-
return function(overrideScopes) {
|
|
93
|
-
var nextScopes = scopeHooks.reduce(function(nextScopes2, param) {
|
|
94
|
-
var {
|
|
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}`];
|
|
95
98
|
return {
|
|
96
99
|
...nextScopes2,
|
|
97
100
|
...currentScope
|
|
98
101
|
};
|
|
99
102
|
}, {});
|
|
100
|
-
return React.useMemo(function() {
|
|
103
|
+
return React.useMemo(function () {
|
|
101
104
|
return {
|
|
102
105
|
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
103
106
|
};
|
|
104
|
-
}, [
|
|
105
|
-
nextScopes
|
|
106
|
-
]);
|
|
107
|
+
}, [nextScopes]);
|
|
107
108
|
};
|
|
108
109
|
};
|
|
109
110
|
return createScope.scopeName = baseScope.scopeName, createScope;
|
|
110
111
|
}
|
|
111
|
-
export {
|
|
112
|
-
|
|
113
|
-
createContextScope
|
|
114
|
-
};
|
|
115
|
-
//# sourceMappingURL=create-context.js.map
|
|
112
|
+
export { createContext, createContextScope };
|
|
113
|
+
//# sourceMappingURL=create-context.native.js.map
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/Users/n8/tamagui/code/core/create-context/src/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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,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
|
-
"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
|
-
}
|
|
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,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QAAA,CACF;IACF;EAEA;EAEF,OAAAH,WAAA,CAAAf,SAAA,GAAAA,SAAA,G","ignoreList":[]}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./create-context";
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./create-context.native.js";
|
|
2
|
+
//# sourceMappingURL=index.native.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-context",
|
|
3
|
-
"version": "1.111.
|
|
3
|
+
"version": "1.111.10",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"exports": {
|
|
24
24
|
"./package.json": "./package.json",
|
|
25
25
|
".": {
|
|
26
|
-
"react-native-import": "./dist/esm/index.native.
|
|
26
|
+
"react-native-import": "./dist/esm/index.native.js",
|
|
27
27
|
"react-native": "./dist/cjs/index.native.js",
|
|
28
28
|
"types": "./types/index.d.ts",
|
|
29
29
|
"import": "./dist/esm/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tamagui/build": "1.111.
|
|
34
|
+
"@tamagui/build": "1.111.10",
|
|
35
35
|
"react": "^18.2.0 || ^19.0.0"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
@@ -1,113 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAS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