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