@tamagui/create-context 2.0.0-rc.36 → 2.0.0-rc.36-1775243248161
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.cjs +57 -45
- package/dist/cjs/create-context.native.js +70 -59
- package/dist/cjs/create-context.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/create-context.mjs +31 -21
- package/dist/esm/create-context.mjs.map +1 -1
- package/dist/esm/create-context.native.js +44 -35
- package/dist/esm/create-context.native.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,49 +2,51 @@ 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
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
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, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var create_context_exports = {};
|
|
33
35
|
__export(create_context_exports, {
|
|
34
36
|
createContext: () => createContext,
|
|
35
37
|
createContextScope: () => createContextScope
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(create_context_exports);
|
|
38
|
-
var React = __toESM(require("react"), 1)
|
|
39
|
-
|
|
40
|
+
var React = __toESM(require("react"), 1);
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
40
42
|
function createContext(rootComponentName, defaultContext) {
|
|
41
43
|
const Context = React.createContext(defaultContext);
|
|
42
44
|
function Provider(props) {
|
|
43
45
|
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
children,
|
|
47
|
+
...context
|
|
48
|
+
} = props;
|
|
49
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
48
50
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
49
51
|
value,
|
|
50
52
|
children
|
|
@@ -61,36 +63,43 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
61
63
|
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
62
64
|
let defaultContexts = [];
|
|
63
65
|
function createContext2(rootComponentName, defaultContext) {
|
|
64
|
-
const BaseContext = React.createContext(defaultContext)
|
|
65
|
-
|
|
66
|
+
const BaseContext = React.createContext(defaultContext);
|
|
67
|
+
const index = defaultContexts.length;
|
|
66
68
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
67
69
|
function Provider(props) {
|
|
68
70
|
const {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
scope,
|
|
72
|
+
children,
|
|
73
|
+
...context
|
|
74
|
+
} = props;
|
|
75
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
76
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
75
77
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
76
78
|
value,
|
|
77
79
|
children
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
function useContext(consumerName, scope, options) {
|
|
81
|
-
const Context = scope?.[scopeName]?.[index] || BaseContext
|
|
82
|
-
|
|
83
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
84
|
+
const context = React.useContext(Context);
|
|
83
85
|
if (context) return context;
|
|
84
86
|
if (defaultContext !== void 0) return defaultContext;
|
|
85
87
|
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
86
|
-
if (options?.fallback)
|
|
88
|
+
if (options?.fallback) {
|
|
89
|
+
if (options?.warn !== false) {
|
|
90
|
+
console.warn(missingContextMessage);
|
|
91
|
+
}
|
|
92
|
+
return options.fallback;
|
|
93
|
+
}
|
|
87
94
|
throw new Error(missingContextMessage);
|
|
88
95
|
}
|
|
89
96
|
return [Provider, useContext];
|
|
90
97
|
}
|
|
91
98
|
const createScope = () => {
|
|
92
|
-
const scopeContexts = defaultContexts.map(defaultContext =>
|
|
93
|
-
|
|
99
|
+
const scopeContexts = defaultContexts.map(defaultContext => {
|
|
100
|
+
return React.createContext(defaultContext);
|
|
101
|
+
});
|
|
102
|
+
return function useScope(scope) {
|
|
94
103
|
const contexts = scope?.[scopeName] || scopeContexts;
|
|
95
104
|
return React.useMemo(() => ({
|
|
96
105
|
[`__scope${scopeName}`]: {
|
|
@@ -100,7 +109,8 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
|
100
109
|
}), [scope, contexts]);
|
|
101
110
|
};
|
|
102
111
|
};
|
|
103
|
-
|
|
112
|
+
createScope.scopeName = scopeName;
|
|
113
|
+
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
104
114
|
}
|
|
105
115
|
function composeContextScopes(...scopes) {
|
|
106
116
|
const baseScope = scopes[0];
|
|
@@ -110,12 +120,13 @@ function composeContextScopes(...scopes) {
|
|
|
110
120
|
useScope: createScope2(),
|
|
111
121
|
scopeName: createScope2.scopeName
|
|
112
122
|
}));
|
|
113
|
-
return function (overrideScopes) {
|
|
123
|
+
return function useComposedScopes(overrideScopes) {
|
|
114
124
|
const nextScopes = scopeHooks.reduce((nextScopes2, {
|
|
115
125
|
useScope,
|
|
116
126
|
scopeName
|
|
117
127
|
}) => {
|
|
118
|
-
const
|
|
128
|
+
const scopeProps = useScope(overrideScopes);
|
|
129
|
+
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
119
130
|
return {
|
|
120
131
|
...nextScopes2,
|
|
121
132
|
...currentScope
|
|
@@ -126,5 +137,6 @@ function composeContextScopes(...scopes) {
|
|
|
126
137
|
}), [nextScopes]);
|
|
127
138
|
};
|
|
128
139
|
};
|
|
129
|
-
|
|
140
|
+
createScope.scopeName = baseScope.scopeName;
|
|
141
|
+
return createScope;
|
|
130
142
|
}
|
|
@@ -4,51 +4,53 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
34
36
|
var create_context_exports = {};
|
|
35
37
|
__export(create_context_exports, {
|
|
36
38
|
createContext: () => createContext,
|
|
37
39
|
createContextScope: () => createContextScope
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(create_context_exports);
|
|
40
|
-
var import_jsx_runtime = require("react/jsx-runtime")
|
|
41
|
-
|
|
42
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
var React = __toESM(require("react"), 1);
|
|
42
44
|
function createContext(rootComponentName, defaultContext) {
|
|
43
45
|
var Context = /* @__PURE__ */React.createContext(defaultContext);
|
|
44
46
|
function Provider(props) {
|
|
45
47
|
var {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
children,
|
|
49
|
+
...context
|
|
50
|
+
} = props;
|
|
51
|
+
var value = React.useMemo(function () {
|
|
52
|
+
return context;
|
|
53
|
+
}, Object.values(context));
|
|
52
54
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
53
55
|
value,
|
|
54
56
|
children
|
|
@@ -63,36 +65,41 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
63
65
|
return [Provider, useContext];
|
|
64
66
|
}
|
|
65
67
|
function createContextScope(scopeName) {
|
|
66
|
-
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []
|
|
67
|
-
|
|
68
|
+
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
69
|
+
var defaultContexts = [];
|
|
68
70
|
function createContext2(rootComponentName, defaultContext) {
|
|
69
|
-
var BaseContext = /* @__PURE__ */React.createContext(defaultContext)
|
|
70
|
-
|
|
71
|
+
var BaseContext = /* @__PURE__ */React.createContext(defaultContext);
|
|
72
|
+
var index = defaultContexts.length;
|
|
71
73
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
72
74
|
function Provider(props) {
|
|
73
|
-
var _scope_scopeName
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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));
|
|
83
85
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
84
86
|
value,
|
|
85
87
|
children
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
function useContext(consumerName, scope, options) {
|
|
89
|
-
var _scope_scopeName
|
|
90
|
-
|
|
91
|
-
|
|
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);
|
|
92
94
|
if (context) return context;
|
|
93
95
|
if (defaultContext !== void 0) return defaultContext;
|
|
94
96
|
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
95
|
-
if (options
|
|
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
|
+
}
|
|
96
103
|
throw new Error(missingContextMessage);
|
|
97
104
|
}
|
|
98
105
|
return [Provider, useContext];
|
|
@@ -101,8 +108,8 @@ function createContextScope(scopeName) {
|
|
|
101
108
|
var scopeContexts = defaultContexts.map(function (defaultContext) {
|
|
102
109
|
return /* @__PURE__ */React.createContext(defaultContext);
|
|
103
110
|
});
|
|
104
|
-
return function (scope) {
|
|
105
|
-
var contexts = scope
|
|
111
|
+
return function useScope(scope) {
|
|
112
|
+
var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
|
|
106
113
|
return React.useMemo(function () {
|
|
107
114
|
return {
|
|
108
115
|
[`__scope${scopeName}`]: {
|
|
@@ -113,10 +120,13 @@ function createContextScope(scopeName) {
|
|
|
113
120
|
}, [scope, contexts]);
|
|
114
121
|
};
|
|
115
122
|
};
|
|
116
|
-
|
|
123
|
+
createScope.scopeName = scopeName;
|
|
124
|
+
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
117
125
|
}
|
|
118
126
|
function composeContextScopes() {
|
|
119
|
-
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++)
|
|
127
|
+
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
128
|
+
scopes[_key] = arguments[_key];
|
|
129
|
+
}
|
|
120
130
|
var baseScope = scopes[0];
|
|
121
131
|
if (scopes.length === 1) return baseScope;
|
|
122
132
|
var createScope = function () {
|
|
@@ -126,14 +136,14 @@ function composeContextScopes() {
|
|
|
126
136
|
scopeName: createScope2.scopeName
|
|
127
137
|
};
|
|
128
138
|
});
|
|
129
|
-
return function (overrideScopes) {
|
|
139
|
+
return function useComposedScopes(overrideScopes) {
|
|
130
140
|
var nextScopes = scopeHooks.reduce(function (nextScopes2, param) {
|
|
131
141
|
var {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
useScope,
|
|
143
|
+
scopeName
|
|
144
|
+
} = param;
|
|
145
|
+
var scopeProps = useScope(overrideScopes);
|
|
146
|
+
var currentScope = scopeProps[`__scope${scopeName}`];
|
|
137
147
|
return {
|
|
138
148
|
...nextScopes2,
|
|
139
149
|
...currentScope
|
|
@@ -146,6 +156,7 @@ function composeContextScopes() {
|
|
|
146
156
|
}, [nextScopes]);
|
|
147
157
|
};
|
|
148
158
|
};
|
|
149
|
-
|
|
159
|
+
createScope.scopeName = baseScope.scopeName;
|
|
160
|
+
return createScope;
|
|
150
161
|
}
|
|
151
162
|
//# sourceMappingURL=create-context.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","create_context_exports","__export","createContext","createContextScope","module","exports","import_jsx_runtime","require","React","__toESM","rootComponentName","defaultContext","Context","Provider","props","children","context","useMemo","Object","values","jsx","useContext","consumerName","Error","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":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","create_context_exports","__export","createContext","createContextScope","module","exports","import_jsx_runtime","require","React","__toESM","rootComponentName","defaultContext","Context","Provider","props","children","context","useMemo","Object","values","jsx","useContext","consumerName","Error","scopeName","createContextScopeDeps","arguments","length","defaultContexts","createContext2","BaseContext","index","_scope_scopeName","scope","options","missingContextMessage","fallback","warn","console","createScope","scopeContexts","map","useScope","contexts"],"sources":["../../src/create-context.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,sBAAA;AAAAC,QAAA,CAAAD,sBAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAGAC,MAAA,CAAAC,OAAuB,GAAAV,YAAA,CAAAK,sBAAA;AAkBZ,IAAAM,kBAAA,GA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CAAAS,cAAiB;IAAA,EAC9C;IAAsB,OACtB,SAAW+B,SAAAT,KAAY;MACvB,IAAAU,QAAA,IAAAV,KAAA,aAAAA,KAAA,uBAAAA,KAAA,CAAAT,SAAA,MAAAgB,aAAA;MAEF,OAAOhC,KAAA,CAAAS,OAAS,aAAkB;QAChC,OAAM;UAIJ,WAAMO,SAAa;YACnB,GAAMS,KAAA;YACN,CAAAT,SAAY,GAAAmB;UACV;QAEJ;MAAa,GACX,CACAV,KAAC,EACHU,QAAA,CACF;IACF;EAEA;EACAJ,WAAO,CAAAf,SAAA,GAAAA,SAAA;EACT,Q","ignoreList":[]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,15 +3,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
7
8
|
get: () => from[key],
|
|
8
9
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
10
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
15
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
-
value:
|
|
16
|
+
value: true
|
|
15
17
|
}), mod);
|
|
16
18
|
var index_exports = {};
|
|
17
19
|
module.exports = __toCommonJS(index_exports);
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -5,15 +5,17 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
9
10
|
get: () => from[key],
|
|
10
11
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
11
12
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
17
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value:
|
|
18
|
+
value: true
|
|
17
19
|
}), mod);
|
|
18
20
|
var index_exports = {};
|
|
19
21
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
|
|
@@ -4,10 +4,10 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
4
4
|
const Context = React.createContext(defaultContext);
|
|
5
5
|
function Provider(props) {
|
|
6
6
|
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
children,
|
|
8
|
+
...context
|
|
9
|
+
} = props;
|
|
10
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
11
11
|
return /* @__PURE__ */jsx(Context.Provider, {
|
|
12
12
|
value,
|
|
13
13
|
children
|
|
@@ -24,36 +24,43 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
24
24
|
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
25
25
|
let defaultContexts = [];
|
|
26
26
|
function createContext2(rootComponentName, defaultContext) {
|
|
27
|
-
const BaseContext = React.createContext(defaultContext)
|
|
28
|
-
|
|
27
|
+
const BaseContext = React.createContext(defaultContext);
|
|
28
|
+
const index = defaultContexts.length;
|
|
29
29
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
30
30
|
function Provider(props) {
|
|
31
31
|
const {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
scope,
|
|
33
|
+
children,
|
|
34
|
+
...context
|
|
35
|
+
} = props;
|
|
36
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
37
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
38
38
|
return /* @__PURE__ */jsx(Context.Provider, {
|
|
39
39
|
value,
|
|
40
40
|
children
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
function useContext(consumerName, scope, options) {
|
|
44
|
-
const Context = scope?.[scopeName]?.[index] || BaseContext
|
|
45
|
-
|
|
44
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
45
|
+
const context = React.useContext(Context);
|
|
46
46
|
if (context) return context;
|
|
47
47
|
if (defaultContext !== void 0) return defaultContext;
|
|
48
48
|
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
49
|
-
if (options?.fallback)
|
|
49
|
+
if (options?.fallback) {
|
|
50
|
+
if (options?.warn !== false) {
|
|
51
|
+
console.warn(missingContextMessage);
|
|
52
|
+
}
|
|
53
|
+
return options.fallback;
|
|
54
|
+
}
|
|
50
55
|
throw new Error(missingContextMessage);
|
|
51
56
|
}
|
|
52
57
|
return [Provider, useContext];
|
|
53
58
|
}
|
|
54
59
|
const createScope = () => {
|
|
55
|
-
const scopeContexts = defaultContexts.map(defaultContext =>
|
|
56
|
-
|
|
60
|
+
const scopeContexts = defaultContexts.map(defaultContext => {
|
|
61
|
+
return React.createContext(defaultContext);
|
|
62
|
+
});
|
|
63
|
+
return function useScope(scope) {
|
|
57
64
|
const contexts = scope?.[scopeName] || scopeContexts;
|
|
58
65
|
return React.useMemo(() => ({
|
|
59
66
|
[`__scope${scopeName}`]: {
|
|
@@ -63,7 +70,8 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
|
63
70
|
}), [scope, contexts]);
|
|
64
71
|
};
|
|
65
72
|
};
|
|
66
|
-
|
|
73
|
+
createScope.scopeName = scopeName;
|
|
74
|
+
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
67
75
|
}
|
|
68
76
|
function composeContextScopes(...scopes) {
|
|
69
77
|
const baseScope = scopes[0];
|
|
@@ -73,12 +81,13 @@ function composeContextScopes(...scopes) {
|
|
|
73
81
|
useScope: createScope2(),
|
|
74
82
|
scopeName: createScope2.scopeName
|
|
75
83
|
}));
|
|
76
|
-
return function (overrideScopes) {
|
|
84
|
+
return function useComposedScopes(overrideScopes) {
|
|
77
85
|
const nextScopes = scopeHooks.reduce((nextScopes2, {
|
|
78
86
|
useScope,
|
|
79
87
|
scopeName
|
|
80
88
|
}) => {
|
|
81
|
-
const
|
|
89
|
+
const scopeProps = useScope(overrideScopes);
|
|
90
|
+
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
82
91
|
return {
|
|
83
92
|
...nextScopes2,
|
|
84
93
|
...currentScope
|
|
@@ -89,7 +98,8 @@ function composeContextScopes(...scopes) {
|
|
|
89
98
|
}), [nextScopes]);
|
|
90
99
|
};
|
|
91
100
|
};
|
|
92
|
-
|
|
101
|
+
createScope.scopeName = baseScope.scopeName;
|
|
102
|
+
return createScope;
|
|
93
103
|
}
|
|
94
104
|
export { createContext, createContextScope };
|
|
95
105
|
//# sourceMappingURL=create-context.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","jsx","createContext","rootComponentName","defaultContext","Context","Provider","props","children","context","value","useMemo","Object","values","useContext","consumerName","Error","createContextScope","scopeName","createContextScopeDeps","defaultContexts","createContext2","BaseContext","index","length","scope","options","missingContextMessage","fallback","warn","console","createScope","scopeContexts","map","contexts","composeContextScopes","scopes","baseScope","scopeHooks","createScope2","
|
|
1
|
+
{"version":3,"names":["React","jsx","createContext","rootComponentName","defaultContext","Context","Provider","props","children","context","value","useMemo","Object","values","useContext","consumerName","Error","createContextScope","scopeName","createContextScopeDeps","defaultContexts","createContext2","BaseContext","index","length","scope","options","missingContextMessage","fallback","warn","console","createScope","scopeContexts","map","useScope","contexts","composeContextScopes","scopes","baseScope","scopeHooks","createScope2","useComposedScopes","overrideScopes","nextScopes","reduce","nextScopes2","scopeProps","currentScope"],"sources":["../../src/create-context.tsx"],"sourcesContent":[null],"mappings":"AAGA,YAAYA,KAAA,MAAW;AAkBZ,SAAAC,GAAA;AAdJ,SAASC,cACdC,iBAAA,EACAC,cAAA,EAIA;EACA,MAAMC,OAAA,GAAUL,KAAA,CAAME,aAAA,CAA4CE,cAAc;EAEhF,SAASE,SAASC,KAAA,EAAyD;IACzE,MAAM;MAAEC,QAAA;MAAU,GAAGC;IAAQ,IAAIF,KAAA;IAGjC,MAAMG,KAAA,GAAQV,KAAA,CAAMW,OAAA,CAAQ,MAAMF,OAAA,EAASG,MAAA,CAAOC,MAAA,CAAOJ,OAAO,CAAC;IACjE,OAAO,eAAAR,GAAA,CAACI,OAAA,CAAQC,QAAA,EAAR;MAAiBI,KAAA;MAAeF;IAAA,CAAS;EACnD;EAEA,SAASM,WAAWC,YAAA,EAA0D;IAC5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;IAEF,OAAO,SAASuB,kBAAkBC,cAAA,EAAgB;MAChD,MAAMC,UAAA,GAAaJ,UAAA,CAAWK,MAAA,CAAO,CAACC,WAAA,EAAY;QAAEX,QAAA;QAAUhB;MAAU,MAAM;QAI5E,MAAM4B,UAAA,GAAaZ,QAAA,CAASQ,cAAc;QAC1C,MAAMK,YAAA,GAAeD,UAAA,CAAW,UAAU5B,SAAS,EAAE;QACrD,OAAO;UAAE,GAAG2B,WAAA;UAAY,GAAGE;QAAa;MAC1C,GAAG,CAAC,CAAC;MAEL,OAAO/C,KAAA,CAAMW,OAAA,CACX,OAAO;QAAE,CAAC,UAAU2B,SAAA,CAAUpB,SAAS,EAAE,GAAGyB;MAAW,IACvD,CAACA,UAAU,CACb;IACF;EACF;EAEAZ,WAAA,CAAYb,SAAA,GAAYoB,SAAA,CAAUpB,SAAA;EAClC,OAAOa,WAAA;AACT","ignoreList":[]}
|
|
@@ -4,12 +4,12 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
4
4
|
var Context = /* @__PURE__ */React.createContext(defaultContext);
|
|
5
5
|
function Provider(props) {
|
|
6
6
|
var {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
children,
|
|
8
|
+
...context
|
|
9
|
+
} = props;
|
|
10
|
+
var value = React.useMemo(function () {
|
|
11
|
+
return context;
|
|
12
|
+
}, Object.values(context));
|
|
13
13
|
return /* @__PURE__ */_jsx(Context.Provider, {
|
|
14
14
|
value,
|
|
15
15
|
children
|
|
@@ -24,36 +24,41 @@ function createContext(rootComponentName, defaultContext) {
|
|
|
24
24
|
return [Provider, useContext];
|
|
25
25
|
}
|
|
26
26
|
function createContextScope(scopeName) {
|
|
27
|
-
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []
|
|
28
|
-
|
|
27
|
+
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
28
|
+
var defaultContexts = [];
|
|
29
29
|
function createContext2(rootComponentName, defaultContext) {
|
|
30
|
-
var BaseContext = /* @__PURE__ */React.createContext(defaultContext)
|
|
31
|
-
|
|
30
|
+
var BaseContext = /* @__PURE__ */React.createContext(defaultContext);
|
|
31
|
+
var index = defaultContexts.length;
|
|
32
32
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
33
33
|
function Provider(props) {
|
|
34
|
-
var _scope_scopeName
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
var _scope_scopeName;
|
|
35
|
+
var {
|
|
36
|
+
scope,
|
|
37
|
+
children,
|
|
38
|
+
...context
|
|
39
|
+
} = props;
|
|
40
|
+
var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
|
|
41
|
+
var value = React.useMemo(function () {
|
|
42
|
+
return context;
|
|
43
|
+
}, Object.values(context));
|
|
44
44
|
return /* @__PURE__ */_jsx(Context.Provider, {
|
|
45
45
|
value,
|
|
46
46
|
children
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
function useContext(consumerName, scope, options) {
|
|
50
|
-
var _scope_scopeName
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
var _scope_scopeName;
|
|
51
|
+
var Context = (scope === null || scope === void 0 ? void 0 : (_scope_scopeName = scope[scopeName]) === null || _scope_scopeName === void 0 ? void 0 : _scope_scopeName[index]) || BaseContext;
|
|
52
|
+
var context = React.useContext(Context);
|
|
53
53
|
if (context) return context;
|
|
54
54
|
if (defaultContext !== void 0) return defaultContext;
|
|
55
55
|
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
56
|
-
if (options
|
|
56
|
+
if (options === null || options === void 0 ? void 0 : options.fallback) {
|
|
57
|
+
if ((options === null || options === void 0 ? void 0 : options.warn) !== false) {
|
|
58
|
+
console.warn(missingContextMessage);
|
|
59
|
+
}
|
|
60
|
+
return options.fallback;
|
|
61
|
+
}
|
|
57
62
|
throw new Error(missingContextMessage);
|
|
58
63
|
}
|
|
59
64
|
return [Provider, useContext];
|
|
@@ -62,8 +67,8 @@ function createContextScope(scopeName) {
|
|
|
62
67
|
var scopeContexts = defaultContexts.map(function (defaultContext) {
|
|
63
68
|
return /* @__PURE__ */React.createContext(defaultContext);
|
|
64
69
|
});
|
|
65
|
-
return function (scope) {
|
|
66
|
-
var contexts = scope
|
|
70
|
+
return function useScope(scope) {
|
|
71
|
+
var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
|
|
67
72
|
return React.useMemo(function () {
|
|
68
73
|
return {
|
|
69
74
|
[`__scope${scopeName}`]: {
|
|
@@ -74,10 +79,13 @@ function createContextScope(scopeName) {
|
|
|
74
79
|
}, [scope, contexts]);
|
|
75
80
|
};
|
|
76
81
|
};
|
|
77
|
-
|
|
82
|
+
createScope.scopeName = scopeName;
|
|
83
|
+
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
78
84
|
}
|
|
79
85
|
function composeContextScopes() {
|
|
80
|
-
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++)
|
|
86
|
+
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
87
|
+
scopes[_key] = arguments[_key];
|
|
88
|
+
}
|
|
81
89
|
var baseScope = scopes[0];
|
|
82
90
|
if (scopes.length === 1) return baseScope;
|
|
83
91
|
var createScope = function () {
|
|
@@ -87,14 +95,14 @@ function composeContextScopes() {
|
|
|
87
95
|
scopeName: createScope2.scopeName
|
|
88
96
|
};
|
|
89
97
|
});
|
|
90
|
-
return function (overrideScopes) {
|
|
98
|
+
return function useComposedScopes(overrideScopes) {
|
|
91
99
|
var nextScopes = scopeHooks.reduce(function (nextScopes2, param) {
|
|
92
100
|
var {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
useScope,
|
|
102
|
+
scopeName
|
|
103
|
+
} = param;
|
|
104
|
+
var scopeProps = useScope(overrideScopes);
|
|
105
|
+
var currentScope = scopeProps[`__scope${scopeName}`];
|
|
98
106
|
return {
|
|
99
107
|
...nextScopes2,
|
|
100
108
|
...currentScope
|
|
@@ -107,7 +115,8 @@ function composeContextScopes() {
|
|
|
107
115
|
}, [nextScopes]);
|
|
108
116
|
};
|
|
109
117
|
};
|
|
110
|
-
|
|
118
|
+
createScope.scopeName = baseScope.scopeName;
|
|
119
|
+
return createScope;
|
|
111
120
|
}
|
|
112
121
|
export { createContext, createContextScope };
|
|
113
122
|
//# sourceMappingURL=create-context.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsx","_jsx","React","createContext","rootComponentName","defaultContext","Context","Provider","props","children","context","value","useMemo","Object","values","useContext","consumerName","Error","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;AAkBZ,YAAAC,KAAA;AAdJ,SAASC,cACdC,iBAAA,EACAC,cAAA,EAIA;EACA,IAAAC,OAAM,kBAAgBJ,KAAA,CAA4CC,aAAA,CAAcE,cAAA;EAEhF,SAASE,SAASC,KAAA,EAAyD;IACzE;
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","React","createContext","rootComponentName","defaultContext","Context","Provider","props","children","context","value","useMemo","Object","values","useContext","consumerName","Error","createContextScope","scopeName","createContextScopeDeps","arguments","length","defaultContexts","createContext2","BaseContext","index","_scope_scopeName","scope","options","missingContextMessage","fallback","warn","console","createScope","scopeContexts","map","useScope","contexts"],"sources":["../../src/create-context.tsx"],"sourcesContent":[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E,cAAA;IACrC;IAAgD,OAC9C,SAAUgC,SAAYT,KAAA;MACtB,IAAAU,QAAW,IAAAV,KAAA,KAAY,QAAAA,KAAA,uBAAAA,KAAA,CAAAT,SAAA,MAAAgB,aAAA;MACvB,OAAAjC,KAAA,CAAAU,OAAA;QAEF,OAAO;UACL,WAAMO,SAAa;YAIjB,GAAMS,KAAA;YACN,CAAAT,SAAM,GAAAmB;UACN;QACF,CAAG;MAEH,IACEV,KAAA,EACAU,QAAC,CACH;IACF;EACF;EAEAJ,WAAA,CAAYf,SAAA,GAAYA,SAAA;EACxB,OAAO,CACTK,cAAA,E","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-context",
|
|
3
|
-
"version": "2.0.0-rc.36",
|
|
3
|
+
"version": "2.0.0-rc.36-1775243248161",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"clean:build": "tamagui-build clean:build"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@tamagui/build": "2.0.0-rc.36",
|
|
38
|
+
"@tamagui/build": "2.0.0-rc.36-1775243248161",
|
|
39
39
|
"react": ">=19"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|