@tamagui/create-context 1.114.4 → 1.115.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.
|
@@ -2,36 +2,53 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf,
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
7
|
var __export = (target, all) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
15
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
21
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
22
|
// file that has been converted to a CommonJS file using a Babel-
|
|
18
23
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
24
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
23
32
|
var create_context_exports = {};
|
|
24
33
|
__export(create_context_exports, {
|
|
25
34
|
createContext: () => createContext,
|
|
26
35
|
createContextScope: () => createContextScope
|
|
27
36
|
});
|
|
28
37
|
module.exports = __toCommonJS(create_context_exports);
|
|
29
|
-
var React = __toESM(require("react")),
|
|
38
|
+
var React = __toESM(require("react")),
|
|
39
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
30
40
|
function createContext(rootComponentName, defaultContext) {
|
|
31
41
|
const Context = React.createContext(defaultContext);
|
|
32
42
|
function Provider(props) {
|
|
33
|
-
const {
|
|
34
|
-
|
|
43
|
+
const {
|
|
44
|
+
children,
|
|
45
|
+
...context
|
|
46
|
+
} = props,
|
|
47
|
+
value = React.useMemo(() => context, Object.values(context));
|
|
48
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
49
|
+
value,
|
|
50
|
+
children
|
|
51
|
+
});
|
|
35
52
|
}
|
|
36
53
|
function useContext(consumerName) {
|
|
37
54
|
const context = React.useContext(Context);
|
|
@@ -44,60 +61,70 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
44
61
|
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
45
62
|
let defaultContexts = [];
|
|
46
63
|
function createContext2(rootComponentName, defaultContext) {
|
|
47
|
-
const BaseContext = React.createContext(defaultContext),
|
|
64
|
+
const BaseContext = React.createContext(defaultContext),
|
|
65
|
+
index = defaultContexts.length;
|
|
48
66
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
49
67
|
function Provider(props) {
|
|
50
|
-
const {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
const {
|
|
69
|
+
scope,
|
|
70
|
+
children,
|
|
71
|
+
...context
|
|
72
|
+
} = props,
|
|
73
|
+
Context = scope?.[scopeName]?.[index] || BaseContext,
|
|
74
|
+
value = React.useMemo(() => context, Object.values(context));
|
|
75
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
76
|
+
value,
|
|
77
|
+
children
|
|
78
|
+
});
|
|
55
79
|
}
|
|
56
80
|
function useContext(consumerName, scope, options) {
|
|
57
|
-
const Context = scope?.[scopeName]?.[index] || BaseContext,
|
|
81
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext,
|
|
82
|
+
context = React.useContext(Context);
|
|
58
83
|
if (context) return context;
|
|
59
84
|
if (defaultContext !== void 0) return defaultContext;
|
|
60
85
|
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
61
|
-
if (options?.fallback)
|
|
62
|
-
return options?.warn !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
86
|
+
if (options?.fallback) return options?.warn !== !1 && console.warn(missingContextMessage), options.fallback;
|
|
63
87
|
throw new Error(missingContextMessage);
|
|
64
88
|
}
|
|
65
89
|
return Provider.displayName = `${rootComponentName}Provider`, [Provider, useContext];
|
|
66
90
|
}
|
|
67
91
|
const createScope = () => {
|
|
68
|
-
const scopeContexts = defaultContexts.map(
|
|
69
|
-
return function(scope) {
|
|
92
|
+
const scopeContexts = defaultContexts.map(defaultContext => React.createContext(defaultContext));
|
|
93
|
+
return function (scope) {
|
|
70
94
|
const contexts = scope?.[scopeName] || scopeContexts;
|
|
71
|
-
return React.useMemo(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
95
|
+
return React.useMemo(() => ({
|
|
96
|
+
[`__scope${scopeName}`]: {
|
|
97
|
+
...scope,
|
|
98
|
+
[scopeName]: contexts
|
|
99
|
+
}
|
|
100
|
+
}), [scope, contexts]);
|
|
75
101
|
};
|
|
76
102
|
};
|
|
77
|
-
return createScope.scopeName = scopeName, [
|
|
78
|
-
createContext2,
|
|
79
|
-
composeContextScopes(createScope, ...createContextScopeDeps)
|
|
80
|
-
];
|
|
103
|
+
return createScope.scopeName = scopeName, [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
81
104
|
}
|
|
82
105
|
function composeContextScopes(...scopes) {
|
|
83
106
|
const baseScope = scopes[0];
|
|
84
107
|
if (scopes.length === 1) return baseScope;
|
|
85
108
|
const createScope = () => {
|
|
86
|
-
const scopeHooks = scopes.map(
|
|
109
|
+
const scopeHooks = scopes.map(createScope2 => ({
|
|
87
110
|
useScope: createScope2(),
|
|
88
111
|
scopeName: createScope2.scopeName
|
|
89
112
|
}));
|
|
90
|
-
return function(overrideScopes) {
|
|
91
|
-
const nextScopes = scopeHooks.reduce((nextScopes2, {
|
|
113
|
+
return function (overrideScopes) {
|
|
114
|
+
const nextScopes = scopeHooks.reduce((nextScopes2, {
|
|
115
|
+
useScope,
|
|
116
|
+
scopeName
|
|
117
|
+
}) => {
|
|
92
118
|
const currentScope = useScope(overrideScopes)[`__scope${scopeName}`];
|
|
93
|
-
return {
|
|
119
|
+
return {
|
|
120
|
+
...nextScopes2,
|
|
121
|
+
...currentScope
|
|
122
|
+
};
|
|
94
123
|
}, {});
|
|
95
|
-
return React.useMemo(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
);
|
|
124
|
+
return React.useMemo(() => ({
|
|
125
|
+
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
126
|
+
}), [nextScopes]);
|
|
99
127
|
};
|
|
100
128
|
};
|
|
101
129
|
return createScope.scopeName = baseScope.scopeName, createScope;
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=create-context.js.map
|
|
130
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./create-context.cjs"), module.exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-context",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -27,11 +27,12 @@
|
|
|
27
27
|
"react-native": "./dist/cjs/index.native.js",
|
|
28
28
|
"types": "./types/index.d.ts",
|
|
29
29
|
"import": "./dist/esm/index.mjs",
|
|
30
|
-
"require": "./dist/cjs/index.
|
|
30
|
+
"require": "./dist/cjs/index.cjs",
|
|
31
|
+
"default": "./dist/cjs/index.native.js"
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@tamagui/build": "1.
|
|
35
|
+
"@tamagui/build": "1.115.1",
|
|
35
36
|
"react": "^18.2.0 || ^19.0.0"
|
|
36
37
|
},
|
|
37
38
|
"publishConfig": {
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
|
-
return to;
|
|
10
|
-
}, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
11
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
12
|
-
var src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./create-context"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|