@tamagui/create-context 1.0.1-beta.73 → 1.0.1-beta.76
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.
|
@@ -1,8 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
1
32
|
import * as React from "react";
|
|
2
33
|
function createContext(rootComponentName, defaultContext) {
|
|
3
34
|
const Context = React.createContext(defaultContext);
|
|
4
35
|
function Provider(props) {
|
|
5
|
-
const { children,
|
|
36
|
+
const _a = props, { children } = _a, context = __objRest(_a, ["children"]);
|
|
6
37
|
const value = React.useMemo(() => context, Object.values(context));
|
|
7
38
|
return /* @__PURE__ */ React.createElement(Context.Provider, {
|
|
8
39
|
value
|
|
@@ -26,7 +57,7 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
|
26
57
|
const index = defaultContexts.length;
|
|
27
58
|
defaultContexts = [...defaultContexts, defaultContext];
|
|
28
59
|
function Provider(props) {
|
|
29
|
-
const { scope, children,
|
|
60
|
+
const _a = props, { scope, children } = _a, context = __objRest(_a, ["scope", "children"]);
|
|
30
61
|
const Context = (scope == null ? void 0 : scope[scopeName][index]) || BaseContext;
|
|
31
62
|
const value = React.useMemo(() => context, Object.values(context));
|
|
32
63
|
return /* @__PURE__ */ React.createElement(Context.Provider, {
|
|
@@ -51,7 +82,7 @@ function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
|
51
82
|
});
|
|
52
83
|
return function useScope(scope) {
|
|
53
84
|
const contexts = (scope == null ? void 0 : scope[scopeName]) || scopeContexts;
|
|
54
|
-
return React.useMemo(() => ({ [`__scope${scopeName}`]: {
|
|
85
|
+
return React.useMemo(() => ({ [`__scope${scopeName}`]: __spreadProps(__spreadValues({}, scope), { [scopeName]: contexts }) }), [scope, contexts]);
|
|
55
86
|
};
|
|
56
87
|
};
|
|
57
88
|
createScope.scopeName = scopeName;
|
|
@@ -70,7 +101,7 @@ function composeContextScopes(...scopes) {
|
|
|
70
101
|
const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
|
|
71
102
|
const scopeProps = useScope(overrideScopes);
|
|
72
103
|
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
73
|
-
return {
|
|
104
|
+
return __spreadValues(__spreadValues({}, nextScopes2), currentScope);
|
|
74
105
|
}, {});
|
|
75
106
|
return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
|
|
76
107
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/create-context.tsx"],
|
|
4
4
|
"sourcesContent": ["// from radix\n// https://github.com/radix-ui/primitives/blob/main/packages/react/context/src/createContext.tsx\n\nimport * as React from 'react'\n\nexport type ScopedProps<P, K extends string> = P & { [Key in `__scope${K}`]?: Scope }\n\nexport function createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType\n) {\n const Context = React.createContext<ContextValueType | undefined>(defaultContext)\n\n function Provider(props: ContextValueType & { children: React.ReactNode }) {\n const { children, ...context } = props\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType\n return <Context.Provider value={value}>{children}</Context.Provider>\n }\n\n function useContext(consumerName: string) {\n const context = React.useContext(Context)\n if (context) return context\n if (defaultContext !== undefined) return defaultContext\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``)\n }\n\n Provider.displayName = rootComponentName + 'Provider'\n return [Provider, useContext] as const\n}\n\n/* -------------------------------------------------------------------------------------------------\n * createContextScope\n * -----------------------------------------------------------------------------------------------*/\n\ntype ScopeHook = (scope: Scope) => { [__scopeProp: string]: Scope }\n\nexport type Scope<C = any> = { [scopeName: string]: React.Context<C>[] } | undefined\n\nexport interface CreateScope {\n scopeName: string\n (): ScopeHook\n}\n\nexport function createContextScope(scopeName: string, createContextScopeDeps: CreateScope[] = []) {\n let defaultContexts: any[] = []\n\n /* -----------------------------------------------------------------------------------------------\n * createContext\n * ---------------------------------------------------------------------------------------------*/\n\n function createContext<ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType\n ) {\n const BaseContext = React.createContext<ContextValueType | undefined>(defaultContext)\n const index = defaultContexts.length\n defaultContexts = [...defaultContexts, defaultContext]\n\n function Provider(\n props: ContextValueType & { scope: Scope<ContextValueType>; children: React.ReactNode }\n ) {\n const { scope, children, ...context } = props\n const Context = scope?.[scopeName][index] || BaseContext\n // Only re-memoize when prop values change\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const value = React.useMemo(() => context, Object.values(context)) as ContextValueType\n return <Context.Provider value={value}>{children}</Context.Provider>\n }\n\n function useContext(consumerName: string, scope: Scope<ContextValueType | undefined>) {\n const Context = scope?.[scopeName][index] || BaseContext\n const context = React.useContext(Context)\n if (context) return context\n if (defaultContext !== undefined) return defaultContext\n // if a defaultContext wasn't specified, it's a required context.\n throw new Error(`\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``)\n }\n\n Provider.displayName = rootComponentName + 'Provider'\n return [Provider, useContext] as const\n }\n\n /* -----------------------------------------------------------------------------------------------\n * createScope\n * ---------------------------------------------------------------------------------------------*/\n\n const createScope: CreateScope = () => {\n const scopeContexts = defaultContexts.map((defaultContext) => {\n return React.createContext(defaultContext)\n })\n return function useScope(scope: Scope) {\n const contexts = scope?.[scopeName] || scopeContexts\n return React.useMemo(\n () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),\n [scope, contexts]\n )\n }\n }\n\n createScope.scopeName = scopeName\n return [createContext, composeContextScopes(createScope, ...createContextScopeDeps)] as const\n}\n\n/* -------------------------------------------------------------------------------------------------\n * composeContextScopes\n * -----------------------------------------------------------------------------------------------*/\n\nfunction composeContextScopes(...scopes: CreateScope[]) {\n const baseScope = scopes[0]\n if (scopes.length === 1) return baseScope\n\n const createScope: CreateScope = () => {\n const scopeHooks = scopes.map((createScope) => ({\n useScope: createScope(),\n scopeName: createScope.scopeName,\n }))\n\n return function useComposedScopes(overrideScopes) {\n const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {\n // We are calling a hook inside a callback which React warns against to avoid inconsistent\n // renders, however, scoping doesn't have render side effects so we ignore the rule.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const scopeProps = useScope(overrideScopes)\n const currentScope = scopeProps[`__scope${scopeName}`]\n return { ...nextScopes, ...currentScope }\n }, {})\n\n return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes])\n }\n }\n\n createScope.scopeName = baseScope.scopeName\n return createScope\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n"],
|
|
5
|
-
"mappings": "AAGA;AAIO,uBACL,mBACA,gBACA;AACA,QAAM,UAAU,MAAM,cAA4C,cAAc;AAEhF,oBAAkB,OAAyD;AACzE,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;AAIO,uBACL,mBACA,gBACA;AACA,QAAM,UAAU,MAAM,cAA4C,cAAc;AAEhF,oBAAkB,OAAyD;AACzE,UAAiC,YAAzB,eAAyB,IAAZ,oBAAY,IAAZ,CAAb;AAGR,UAAM,QAAQ,MAAM,QAAQ,MAAM,SAAS,OAAO,OAAO,OAAO,CAAC;AACjE,WAAO,oCAAC,QAAQ,UAAR;AAAA,MAAiB;AAAA,OAAe,QAAS;AAAA,EACnD;AAEA,sBAAoB,cAAsB;AACxC,UAAM,UAAU,MAAM,WAAW,OAAO;AACxC,QAAI;AAAS,aAAO;AACpB,QAAI,mBAAmB;AAAW,aAAO;AAEzC,UAAM,IAAI,MAAM,KAAK,wCAAwC,qBAAqB;AAAA,EACpF;AAEA,WAAS,cAAc,oBAAoB;AAC3C,SAAO,CAAC,UAAU,UAAU;AAC9B;AAeO,4BAA4B,WAAmB,yBAAwC,CAAC,GAAG;AAChG,MAAI,kBAAyB,CAAC;AAM9B,0BACE,mBACA,gBACA;AACA,UAAM,cAAc,MAAM,cAA4C,cAAc;AACpF,UAAM,QAAQ,gBAAgB;AAC9B,sBAAkB,CAAC,GAAG,iBAAiB,cAAc;AAErD,sBACE,OACA;AACA,YAAwC,YAAhC,SAAO,aAAyB,IAAZ,oBAAY,IAAZ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Aa,SAAS,cAAc;AAC1C,cAAM,eAAe,WAAW,UAAU;AAC1C,eAAO,kCAAK,cAAe;AAAA,MAC7B,GAAG,CAAC,CAAC;AAEL,aAAO,MAAM,QAAQ,MAAO,GAAE,CAAC,UAAU,UAAU,cAAc,WAAW,IAAI,CAAC,UAAU,CAAC;AAAA,IAC9F;AAAA,EACF;AAEA,cAAY,YAAY,UAAU;AAClC,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/create-context",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.76",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"react": "*"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
23
|
+
"@tamagui/build": "^1.0.1-beta.76",
|
|
24
24
|
"react": "*"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|