@hanzogui/create-context 8.3.0 → 8.3.2
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.js +109 -0
- package/dist/cjs/create-context.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/create-context.js +104 -0
- package/dist/esm/create-context.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +13 -13
- package/src/index.ts +1 -1
- package/types/create-context.d.ts +27 -20
- package/types/create-context.d.ts.map +1 -11
- package/types/index.d.ts +1 -2
- package/types/index.d.ts.map +1 -11
- package/dist/cjs/create-context.cjs +0 -142
- package/dist/cjs/create-context.native.js +0 -162
- package/dist/cjs/create-context.native.js.map +0 -1
- package/dist/cjs/index.cjs +0 -20
- package/dist/cjs/index.native.js +0 -23
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/esm/create-context.mjs +0 -105
- package/dist/esm/create-context.mjs.map +0 -1
- package/dist/esm/create-context.native.js +0 -122
- package/dist/esm/create-context.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -2
- package/dist/esm/index.native.js.map +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createContext = createContext;
|
|
4
|
+
exports.createContextScope = createContextScope;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
// from radix
|
|
8
|
+
// https://github.com/radix-ui/primitives/blob/main/packages/react/context/src/createContext.tsx
|
|
9
|
+
const React = tslib_1.__importStar(require("react"));
|
|
10
|
+
function createContext(rootComponentName, defaultContext) {
|
|
11
|
+
const Context = React.createContext(defaultContext);
|
|
12
|
+
function Provider(props) {
|
|
13
|
+
const { children, ...context } = props;
|
|
14
|
+
// Only re-memoize when prop values change
|
|
15
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
16
|
+
return (0, jsx_runtime_1.jsx)(Context.Provider, { value: value, children: children });
|
|
17
|
+
}
|
|
18
|
+
function useContext(consumerName) {
|
|
19
|
+
const context = React.useContext(Context);
|
|
20
|
+
if (context)
|
|
21
|
+
return context;
|
|
22
|
+
if (defaultContext !== undefined)
|
|
23
|
+
return defaultContext;
|
|
24
|
+
// if a defaultContext wasn't specified, it's a required context.
|
|
25
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
26
|
+
}
|
|
27
|
+
return [Provider, useContext];
|
|
28
|
+
}
|
|
29
|
+
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
30
|
+
let defaultContexts = [];
|
|
31
|
+
/* -----------------------------------------------------------------------------------------------
|
|
32
|
+
* createContext
|
|
33
|
+
* ---------------------------------------------------------------------------------------------*/
|
|
34
|
+
function createContext(rootComponentName, defaultContext) {
|
|
35
|
+
const BaseContext = React.createContext(defaultContext);
|
|
36
|
+
const index = defaultContexts.length;
|
|
37
|
+
defaultContexts = [...defaultContexts, defaultContext];
|
|
38
|
+
function Provider(props) {
|
|
39
|
+
const { scope, children, ...context } = props;
|
|
40
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
41
|
+
// Only re-memoize when prop values change
|
|
42
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
43
|
+
return (0, jsx_runtime_1.jsx)(Context.Provider, { value: value, children: children });
|
|
44
|
+
}
|
|
45
|
+
function useContext(consumerName, scope, options) {
|
|
46
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
47
|
+
const context = React.useContext(Context);
|
|
48
|
+
if (context)
|
|
49
|
+
return context;
|
|
50
|
+
// if a defaultContext wasn't specified, it's a required context.
|
|
51
|
+
if (defaultContext !== undefined)
|
|
52
|
+
return defaultContext;
|
|
53
|
+
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
54
|
+
// fallback can be given per-hook as well
|
|
55
|
+
if (options?.fallback) {
|
|
56
|
+
if (options?.warn !== false) {
|
|
57
|
+
console.warn(missingContextMessage);
|
|
58
|
+
}
|
|
59
|
+
return options.fallback;
|
|
60
|
+
}
|
|
61
|
+
throw new Error(missingContextMessage);
|
|
62
|
+
}
|
|
63
|
+
return [Provider, useContext];
|
|
64
|
+
}
|
|
65
|
+
/* -----------------------------------------------------------------------------------------------
|
|
66
|
+
* createScope
|
|
67
|
+
* ---------------------------------------------------------------------------------------------*/
|
|
68
|
+
const createScope = () => {
|
|
69
|
+
const scopeContexts = defaultContexts.map((defaultContext) => {
|
|
70
|
+
return React.createContext(defaultContext);
|
|
71
|
+
});
|
|
72
|
+
return function useScope(scope) {
|
|
73
|
+
const contexts = scope?.[scopeName] || scopeContexts;
|
|
74
|
+
return React.useMemo(() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }), [scope, contexts]);
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
createScope.scopeName = scopeName;
|
|
78
|
+
return [
|
|
79
|
+
createContext,
|
|
80
|
+
composeContextScopes(createScope, ...createContextScopeDeps),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
/* -------------------------------------------------------------------------------------------------
|
|
84
|
+
* composeContextScopes
|
|
85
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
86
|
+
function composeContextScopes(...scopes) {
|
|
87
|
+
const baseScope = scopes[0];
|
|
88
|
+
if (scopes.length === 1)
|
|
89
|
+
return baseScope;
|
|
90
|
+
const createScope = () => {
|
|
91
|
+
const scopeHooks = scopes.map((createScope) => ({
|
|
92
|
+
useScope: createScope(),
|
|
93
|
+
scopeName: createScope.scopeName,
|
|
94
|
+
}));
|
|
95
|
+
return function useComposedScopes(overrideScopes) {
|
|
96
|
+
const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {
|
|
97
|
+
// We are calling a hook inside a callback which React warns against to avoid inconsistent
|
|
98
|
+
// renders, however, scoping doesn't have render side effects so we ignore the rule.
|
|
99
|
+
const scopeProps = useScope(overrideScopes);
|
|
100
|
+
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
101
|
+
return { ...nextScopes, ...currentScope };
|
|
102
|
+
}, {});
|
|
103
|
+
return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
createScope.scopeName = baseScope.scopeName;
|
|
107
|
+
return createScope;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=create-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-context.js","sourceRoot":"","sources":["../../src/create-context.tsx"],"names":[],"mappings":";;;;;;AAAA,aAAa;AACb,gGAAgG;AAEhG,MAAY,KAAK,0CAAa;AAI9B,uBACE,iBAAyB,EACzB,cAAiC;IAKjC,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAA+B,cAAc,CAAC,CAAA;IAEjF,SAAS,QAAQ,CAAC,KAAuD;QACvE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAA;QACtC,0CAA0C;QAE1C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAqB,CAAA;QACtF,OAAO,uBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAoB,CAAA;IACtE,CAAC;IAED,SAAS,UAAU,CAAC,YAAoB;QACtC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QACzC,IAAI,OAAO;YAAE,OAAO,OAAc,CAAA;QAClC,IAAI,cAAc,KAAK,SAAS;YAAE,OAAO,cAAqB,CAAA;Q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
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// from radix
|
|
3
|
+
// https://github.com/radix-ui/primitives/blob/main/packages/react/context/src/createContext.tsx
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
export function createContext(rootComponentName, defaultContext) {
|
|
6
|
+
const Context = React.createContext(defaultContext);
|
|
7
|
+
function Provider(props) {
|
|
8
|
+
const { children, ...context } = props;
|
|
9
|
+
// Only re-memoize when prop values change
|
|
10
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
11
|
+
return _jsx(Context.Provider, { value: value, children: children });
|
|
12
|
+
}
|
|
13
|
+
function useContext(consumerName) {
|
|
14
|
+
const context = React.useContext(Context);
|
|
15
|
+
if (context)
|
|
16
|
+
return context;
|
|
17
|
+
if (defaultContext !== undefined)
|
|
18
|
+
return defaultContext;
|
|
19
|
+
// if a defaultContext wasn't specified, it's a required context.
|
|
20
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
21
|
+
}
|
|
22
|
+
return [Provider, useContext];
|
|
23
|
+
}
|
|
24
|
+
export function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
25
|
+
let defaultContexts = [];
|
|
26
|
+
/* -----------------------------------------------------------------------------------------------
|
|
27
|
+
* createContext
|
|
28
|
+
* ---------------------------------------------------------------------------------------------*/
|
|
29
|
+
function createContext(rootComponentName, defaultContext) {
|
|
30
|
+
const BaseContext = React.createContext(defaultContext);
|
|
31
|
+
const index = defaultContexts.length;
|
|
32
|
+
defaultContexts = [...defaultContexts, defaultContext];
|
|
33
|
+
function Provider(props) {
|
|
34
|
+
const { scope, children, ...context } = props;
|
|
35
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
36
|
+
// Only re-memoize when prop values change
|
|
37
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
38
|
+
return _jsx(Context.Provider, { value: value, children: children });
|
|
39
|
+
}
|
|
40
|
+
function useContext(consumerName, scope, options) {
|
|
41
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
42
|
+
const context = React.useContext(Context);
|
|
43
|
+
if (context)
|
|
44
|
+
return context;
|
|
45
|
+
// if a defaultContext wasn't specified, it's a required context.
|
|
46
|
+
if (defaultContext !== undefined)
|
|
47
|
+
return defaultContext;
|
|
48
|
+
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
49
|
+
// fallback can be given per-hook as well
|
|
50
|
+
if (options?.fallback) {
|
|
51
|
+
if (options?.warn !== false) {
|
|
52
|
+
console.warn(missingContextMessage);
|
|
53
|
+
}
|
|
54
|
+
return options.fallback;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(missingContextMessage);
|
|
57
|
+
}
|
|
58
|
+
return [Provider, useContext];
|
|
59
|
+
}
|
|
60
|
+
/* -----------------------------------------------------------------------------------------------
|
|
61
|
+
* createScope
|
|
62
|
+
* ---------------------------------------------------------------------------------------------*/
|
|
63
|
+
const createScope = () => {
|
|
64
|
+
const scopeContexts = defaultContexts.map((defaultContext) => {
|
|
65
|
+
return React.createContext(defaultContext);
|
|
66
|
+
});
|
|
67
|
+
return function useScope(scope) {
|
|
68
|
+
const contexts = scope?.[scopeName] || scopeContexts;
|
|
69
|
+
return React.useMemo(() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }), [scope, contexts]);
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
createScope.scopeName = scopeName;
|
|
73
|
+
return [
|
|
74
|
+
createContext,
|
|
75
|
+
composeContextScopes(createScope, ...createContextScopeDeps),
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
/* -------------------------------------------------------------------------------------------------
|
|
79
|
+
* composeContextScopes
|
|
80
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
81
|
+
function composeContextScopes(...scopes) {
|
|
82
|
+
const baseScope = scopes[0];
|
|
83
|
+
if (scopes.length === 1)
|
|
84
|
+
return baseScope;
|
|
85
|
+
const createScope = () => {
|
|
86
|
+
const scopeHooks = scopes.map((createScope) => ({
|
|
87
|
+
useScope: createScope(),
|
|
88
|
+
scopeName: createScope.scopeName,
|
|
89
|
+
}));
|
|
90
|
+
return function useComposedScopes(overrideScopes) {
|
|
91
|
+
const nextScopes = scopeHooks.reduce((nextScopes, { useScope, scopeName }) => {
|
|
92
|
+
// We are calling a hook inside a callback which React warns against to avoid inconsistent
|
|
93
|
+
// renders, however, scoping doesn't have render side effects so we ignore the rule.
|
|
94
|
+
const scopeProps = useScope(overrideScopes);
|
|
95
|
+
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
96
|
+
return { ...nextScopes, ...currentScope };
|
|
97
|
+
}, {});
|
|
98
|
+
return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
createScope.scopeName = baseScope.scopeName;
|
|
102
|
+
return createScope;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=create-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-context.js","sourceRoot":"","sources":["../../src/create-context.tsx"],"names":[],"mappings":";AAAA,aAAa;AACb,gGAAgG;AAEhG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,UAAU,aAAa,CAC3B,iBAAyB,EACzB,cAAiC;IAKjC,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAA+B,cAAc,CAAC,CAAA;IAEjF,SAAS,QAAQ,CAAC,KAAuD;QACvE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAA;QACtC,0CAA0C;QAE1C,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAqB,CAAA;QACtF,OAAO,KAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAoB,CAAA;I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AAW,CAAA;AACpB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from './create-context.js';
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzogui/create-context",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.2",
|
|
4
4
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,36 +10,36 @@
|
|
|
10
10
|
],
|
|
11
11
|
"type": "module",
|
|
12
12
|
"sideEffects": false,
|
|
13
|
-
"main": "dist/cjs",
|
|
14
|
-
"module": "dist/esm",
|
|
13
|
+
"main": "./dist/cjs/index.js",
|
|
14
|
+
"module": "./dist/esm/index.js",
|
|
15
15
|
"types": "./types/index.d.ts",
|
|
16
16
|
"exports": {
|
|
17
17
|
"./package.json": "./package.json",
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./types/index.d.ts",
|
|
20
|
-
"react-native": "./dist/esm/index.
|
|
21
|
-
"browser": "./dist/esm/index.
|
|
22
|
-
"module": "./dist/esm/index.
|
|
23
|
-
"import": "./dist/esm/index.
|
|
24
|
-
"require": "./dist/cjs/index.
|
|
25
|
-
"default": "./dist/esm/index.
|
|
20
|
+
"react-native": "./dist/esm/index.js",
|
|
21
|
+
"browser": "./dist/esm/index.js",
|
|
22
|
+
"module": "./dist/esm/index.js",
|
|
23
|
+
"import": "./dist/esm/index.js",
|
|
24
|
+
"require": "./dist/cjs/index.js",
|
|
25
|
+
"default": "./dist/esm/index.js"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "hanzogui-build",
|
|
32
|
+
"build": "hanzogui-build --skip-native",
|
|
33
33
|
"watch": "hanzogui-build --watch",
|
|
34
34
|
"clean": "hanzogui-build clean",
|
|
35
35
|
"clean:build": "hanzogui-build clean:build"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@hanzogui/build": "8.3.
|
|
39
|
-
"react": "
|
|
38
|
+
"@hanzogui/build": "8.3.2",
|
|
39
|
+
"react": "19.2.8"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"react": ">=19"
|
|
42
|
+
"react": ">=19.2.8"
|
|
43
43
|
},
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './create-context'
|
|
1
|
+
export * from './create-context.tsx'
|
|
@@ -1,28 +1,35 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
export type ScopedProps<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}) => React.JSX.Element,
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type ScopedProps<P, K extends string> = P & {
|
|
3
|
+
[Key in `__scope${K}`]?: Scope;
|
|
4
|
+
};
|
|
5
|
+
export declare function createContext<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType): readonly [
|
|
6
|
+
(props: ContextValueType & {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}) => React.JSX.Element,
|
|
9
|
+
(consumerName: string) => Exclude<ContextValueType | undefined, undefined>
|
|
10
|
+
];
|
|
9
11
|
type ScopeHook = (scope: Scope) => {
|
|
10
|
-
|
|
12
|
+
[__scopeProp: string]: Scope;
|
|
11
13
|
};
|
|
12
14
|
export type Scope<C = any> = {
|
|
13
|
-
|
|
15
|
+
[scopeName: string]: React.Context<C>[];
|
|
14
16
|
} | undefined;
|
|
15
17
|
export interface CreateScope {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
scopeName: string;
|
|
19
|
+
(): ScopeHook;
|
|
18
20
|
}
|
|
19
|
-
export declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
export declare function createContextScope(scopeName: string, createContextScopeDeps?: CreateScope[]): readonly [
|
|
22
|
+
<ContextValueType extends object | null>(rootComponentName: string, defaultContext?: ContextValueType) => readonly [
|
|
23
|
+
(props: ContextValueType & {
|
|
24
|
+
scope: Scope<ContextValueType>;
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
}) => import('react/jsx-runtime').JSX.Element,
|
|
27
|
+
(consumerName: string, scope: Scope<ContextValueType | undefined>, options?: {
|
|
28
|
+
warn?: boolean;
|
|
29
|
+
fallback?: Partial<ContextValueType>;
|
|
30
|
+
}) => ContextValueType
|
|
31
|
+
],
|
|
32
|
+
CreateScope
|
|
33
|
+
];
|
|
26
34
|
export {};
|
|
27
|
-
|
|
28
35
|
//# sourceMappingURL=create-context.d.ts.map
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAGA,YAAY,WAAW;AAEvB,YAAY;CAAY;CAAG;IAAoB,OAAO,iBAAiB,QAAO;AAE9E,OAAO,iBAAS,cAAc,wCAC5B,2BACA,iBAAiB,8BAEhB,OAAO,mBAAmB;CAAE,UAAU,MAAM;MAAgB,MAAM,IAAI,UACtE,yBAAyB,QAAQ;KA2B/B,aAAa,OAAO,UAAU;wBAAyB;;AAE5D,YAAY,MAAM,WAAW;sBAAuB,MAAM,QAAQ;;AAElE,iBAAiB,YAAY;CAC3B;KACI;;AAGN,OAAO,iBAAS,mBACd,mBACA,yBAAwB,2BAEvB,wCACC,2BACA,iBAAiB,gCAGf,OAAO,mBAAmB;CACxB,OAAO,MAAM;CACb,UAAU,MAAM;aAER,mCAEV,sBACA,OAAO,MAAM,+BACb,UAAU;CACR;CACA,WAAW,QAAQ;MAElB,mBAEP",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/create-context.tsx"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
8
|
-
"sourcesContent": [
|
|
9
|
-
"// 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): readonly [\n (props: ContextValueType & { children: React.ReactNode }) => React.JSX.Element,\n (consumerName: string) => Exclude<ContextValueType | undefined, undefined>,\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\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): Exclude<typeof context, undefined> {\n const context = React.useContext(Context)\n if (context) return context as any\n if (defaultContext !== undefined) return defaultContext as any\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 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(\n scopeName: string,\n createContextScopeDeps: CreateScope[] = []\n): readonly [\n <ContextValueType extends object | null>(\n rootComponentName: string,\n defaultContext?: ContextValueType\n ) => readonly [\n (\n props: ContextValueType & {\n scope: Scope<ContextValueType>\n children: React.ReactNode\n }\n ) => import('react/jsx-runtime').JSX.Element,\n (\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options?: {\n warn?: boolean\n fallback?: Partial<ContextValueType>\n }\n ) => ContextValueType,\n ],\n CreateScope,\n] {\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 & {\n scope: Scope<ContextValueType>\n children: React.ReactNode\n }\n ) {\n const { scope, children, ...context } = props\n const Context = scope?.[scopeName]?.[index] || BaseContext\n // Only re-memoize when prop values change\n\n const value = React.useMemo(\n () => context,\n Object.values(context)\n ) as ContextValueType\n return <Context.Provider value={value}>{children}</Context.Provider>\n }\n\n function useContext(\n consumerName: string,\n scope: Scope<ContextValueType | undefined>,\n options?: {\n warn?: boolean\n fallback?: Partial<ContextValueType>\n }\n ) {\n const Context = scope?.[scopeName]?.[index] || BaseContext\n const context = React.useContext(Context)\n if (context) return context\n // if a defaultContext wasn't specified, it's a required context.\n if (defaultContext !== undefined) return defaultContext\n const missingContextMessage = `\\`${consumerName}\\` must be used within \\`${rootComponentName}\\``\n // fallback can be given per-hook as well\n if (options?.fallback) {\n if (options?.warn !== false) {\n console.warn(missingContextMessage)\n }\n return options.fallback as ContextValueType\n }\n throw new Error(missingContextMessage)\n }\n\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\n return [\n createContext,\n composeContextScopes(createScope, ...createContextScopeDeps),\n ] 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\n const scopeProps = useScope(overrideScopes)\n const currentScope = scopeProps[`__scope${scopeName}`]\n return { ...nextScopes, ...currentScope }\n }, {})\n\n return React.useMemo(\n () => ({ [`__scope${baseScope.scopeName}`]: nextScopes }),\n [nextScopes]\n )\n }\n }\n\n createScope.scopeName = baseScope.scopeName\n return createScope\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"create-context.d.ts","sourceRoot":"","sources":["../src/create-context.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;KAAG,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK;CAAE,CAAA;AAErF,wBAAgB,aAAa,CAAC,gBAAgB,SAAS,MAAM,GAAG,IAAI,EAClE,iBAAiB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CAAA;SACrC,KACE,gBAAgB;KACtB;IACD,WAAW;CACZ,CAkFA"}
|
package/types/index.d.ts
CHANGED
package/types/index.d.ts.map
CHANGED
|
@@ -1,11 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"mappings": "AAAA,cAAc",
|
|
3
|
-
"names": [],
|
|
4
|
-
"sources": [
|
|
5
|
-
"src/index.ts"
|
|
6
|
-
],
|
|
7
|
-
"version": 3,
|
|
8
|
-
"sourcesContent": [
|
|
9
|
-
"export * from './create-context'\n"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
34
|
-
var create_context_exports = {};
|
|
35
|
-
__export(create_context_exports, {
|
|
36
|
-
createContext: () => createContext,
|
|
37
|
-
createContextScope: () => createContextScope
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(create_context_exports);
|
|
40
|
-
var React = __toESM(require("react"), 1);
|
|
41
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
-
function createContext(rootComponentName, defaultContext) {
|
|
43
|
-
const Context = React.createContext(defaultContext);
|
|
44
|
-
function Provider(props) {
|
|
45
|
-
const {
|
|
46
|
-
children,
|
|
47
|
-
...context
|
|
48
|
-
} = props;
|
|
49
|
-
const value = React.useMemo(() => context, Object.values(context));
|
|
50
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
51
|
-
value,
|
|
52
|
-
children
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function useContext(consumerName) {
|
|
56
|
-
const context = React.useContext(Context);
|
|
57
|
-
if (context) return context;
|
|
58
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
59
|
-
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
60
|
-
}
|
|
61
|
-
return [Provider, useContext];
|
|
62
|
-
}
|
|
63
|
-
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
64
|
-
let defaultContexts = [];
|
|
65
|
-
function createContext2(rootComponentName, defaultContext) {
|
|
66
|
-
const BaseContext = React.createContext(defaultContext);
|
|
67
|
-
const index = defaultContexts.length;
|
|
68
|
-
defaultContexts = [...defaultContexts, defaultContext];
|
|
69
|
-
function Provider(props) {
|
|
70
|
-
const {
|
|
71
|
-
scope,
|
|
72
|
-
children,
|
|
73
|
-
...context
|
|
74
|
-
} = props;
|
|
75
|
-
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
76
|
-
const value = React.useMemo(() => context, Object.values(context));
|
|
77
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
78
|
-
value,
|
|
79
|
-
children
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function useContext(consumerName, scope, options) {
|
|
83
|
-
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
84
|
-
const context = React.useContext(Context);
|
|
85
|
-
if (context) return context;
|
|
86
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
87
|
-
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
88
|
-
if (options?.fallback) {
|
|
89
|
-
if (options?.warn !== false) {
|
|
90
|
-
console.warn(missingContextMessage);
|
|
91
|
-
}
|
|
92
|
-
return options.fallback;
|
|
93
|
-
}
|
|
94
|
-
throw new Error(missingContextMessage);
|
|
95
|
-
}
|
|
96
|
-
return [Provider, useContext];
|
|
97
|
-
}
|
|
98
|
-
const createScope = () => {
|
|
99
|
-
const scopeContexts = defaultContexts.map(defaultContext => {
|
|
100
|
-
return React.createContext(defaultContext);
|
|
101
|
-
});
|
|
102
|
-
return function useScope(scope) {
|
|
103
|
-
const contexts = scope?.[scopeName] || scopeContexts;
|
|
104
|
-
return React.useMemo(() => ({
|
|
105
|
-
[`__scope${scopeName}`]: {
|
|
106
|
-
...scope,
|
|
107
|
-
[scopeName]: contexts
|
|
108
|
-
}
|
|
109
|
-
}), [scope, contexts]);
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
createScope.scopeName = scopeName;
|
|
113
|
-
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
114
|
-
}
|
|
115
|
-
function composeContextScopes(...scopes) {
|
|
116
|
-
const baseScope = scopes[0];
|
|
117
|
-
if (scopes.length === 1) return baseScope;
|
|
118
|
-
const createScope = () => {
|
|
119
|
-
const scopeHooks = scopes.map(createScope2 => ({
|
|
120
|
-
useScope: createScope2(),
|
|
121
|
-
scopeName: createScope2.scopeName
|
|
122
|
-
}));
|
|
123
|
-
return function useComposedScopes(overrideScopes) {
|
|
124
|
-
const nextScopes = scopeHooks.reduce((nextScopes2, {
|
|
125
|
-
useScope,
|
|
126
|
-
scopeName
|
|
127
|
-
}) => {
|
|
128
|
-
const scopeProps = useScope(overrideScopes);
|
|
129
|
-
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
130
|
-
return {
|
|
131
|
-
...nextScopes2,
|
|
132
|
-
...currentScope
|
|
133
|
-
};
|
|
134
|
-
}, {});
|
|
135
|
-
return React.useMemo(() => ({
|
|
136
|
-
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
137
|
-
}), [nextScopes]);
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
createScope.scopeName = baseScope.scopeName;
|
|
141
|
-
return createScope;
|
|
142
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
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, {
|
|
18
|
-
get: () => from[key],
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
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);
|
|
36
|
-
var create_context_exports = {};
|
|
37
|
-
__export(create_context_exports, {
|
|
38
|
-
createContext: () => createContext,
|
|
39
|
-
createContextScope: () => createContextScope
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(create_context_exports);
|
|
42
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
-
var React = __toESM(require("react"), 1);
|
|
44
|
-
function createContext(rootComponentName, defaultContext) {
|
|
45
|
-
var Context = /* @__PURE__ */React.createContext(defaultContext);
|
|
46
|
-
function Provider(props) {
|
|
47
|
-
var {
|
|
48
|
-
children,
|
|
49
|
-
...context
|
|
50
|
-
} = props;
|
|
51
|
-
var value = React.useMemo(function () {
|
|
52
|
-
return context;
|
|
53
|
-
}, Object.values(context));
|
|
54
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
55
|
-
value,
|
|
56
|
-
children
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
function useContext(consumerName) {
|
|
60
|
-
var context = React.useContext(Context);
|
|
61
|
-
if (context) return context;
|
|
62
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
63
|
-
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
64
|
-
}
|
|
65
|
-
return [Provider, useContext];
|
|
66
|
-
}
|
|
67
|
-
function createContextScope(scopeName) {
|
|
68
|
-
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
69
|
-
var defaultContexts = [];
|
|
70
|
-
function createContext2(rootComponentName, defaultContext) {
|
|
71
|
-
var BaseContext = /* @__PURE__ */React.createContext(defaultContext);
|
|
72
|
-
var index = defaultContexts.length;
|
|
73
|
-
defaultContexts = [...defaultContexts, defaultContext];
|
|
74
|
-
function Provider(props) {
|
|
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));
|
|
85
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Context.Provider, {
|
|
86
|
-
value,
|
|
87
|
-
children
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function useContext(consumerName, scope, options) {
|
|
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);
|
|
94
|
-
if (context) return context;
|
|
95
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
96
|
-
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
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
|
-
}
|
|
103
|
-
throw new Error(missingContextMessage);
|
|
104
|
-
}
|
|
105
|
-
return [Provider, useContext];
|
|
106
|
-
}
|
|
107
|
-
var createScope = function () {
|
|
108
|
-
var scopeContexts = defaultContexts.map(function (defaultContext) {
|
|
109
|
-
return /* @__PURE__ */React.createContext(defaultContext);
|
|
110
|
-
});
|
|
111
|
-
return function useScope(scope) {
|
|
112
|
-
var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
|
|
113
|
-
return React.useMemo(function () {
|
|
114
|
-
return {
|
|
115
|
-
[`__scope${scopeName}`]: {
|
|
116
|
-
...scope,
|
|
117
|
-
[scopeName]: contexts
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}, [scope, contexts]);
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
createScope.scopeName = scopeName;
|
|
124
|
-
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
125
|
-
}
|
|
126
|
-
function composeContextScopes() {
|
|
127
|
-
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
128
|
-
scopes[_key] = arguments[_key];
|
|
129
|
-
}
|
|
130
|
-
var baseScope = scopes[0];
|
|
131
|
-
if (scopes.length === 1) return baseScope;
|
|
132
|
-
var createScope = function () {
|
|
133
|
-
var scopeHooks = scopes.map(function (createScope2) {
|
|
134
|
-
return {
|
|
135
|
-
useScope: createScope2(),
|
|
136
|
-
scopeName: createScope2.scopeName
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
return function useComposedScopes(overrideScopes) {
|
|
140
|
-
var nextScopes = scopeHooks.reduce(function (nextScopes2, param) {
|
|
141
|
-
var {
|
|
142
|
-
useScope,
|
|
143
|
-
scopeName
|
|
144
|
-
} = param;
|
|
145
|
-
var scopeProps = useScope(overrideScopes);
|
|
146
|
-
var currentScope = scopeProps[`__scope${scopeName}`];
|
|
147
|
-
return {
|
|
148
|
-
...nextScopes2,
|
|
149
|
-
...currentScope
|
|
150
|
-
};
|
|
151
|
-
}, {});
|
|
152
|
-
return React.useMemo(function () {
|
|
153
|
-
return {
|
|
154
|
-
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
155
|
-
};
|
|
156
|
-
}, [nextScopes]);
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
createScope.scopeName = baseScope.scopeName;
|
|
160
|
-
return createScope;
|
|
161
|
-
}
|
|
162
|
-
//# sourceMappingURL=create-context.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,GAAAC,OAAA;AAdJ,IAAAC,KAAS,GAAAC,OA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tB,SAAW+B,QAAAH,CAAAN,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
DELETED
|
@@ -1,20 +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)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
-
get: () => from[key],
|
|
9
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value: true
|
|
17
|
-
}), mod);
|
|
18
|
-
var index_exports = {};
|
|
19
|
-
module.exports = __toCommonJS(index_exports);
|
|
20
|
-
__reExport(index_exports, require("./create-context.cjs"), module.exports);
|
package/dist/cjs/index.native.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
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, {
|
|
10
|
-
get: () => from[key],
|
|
11
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return to;
|
|
15
|
-
};
|
|
16
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
18
|
-
value: true
|
|
19
|
-
}), mod);
|
|
20
|
-
var index_exports = {};
|
|
21
|
-
module.exports = __toCommonJS(index_exports);
|
|
22
|
-
__reExport(index_exports, require("./create-context.native.js"), module.exports);
|
|
23
|
-
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
function createContext(rootComponentName, defaultContext) {
|
|
4
|
-
const Context = React.createContext(defaultContext);
|
|
5
|
-
function Provider(props) {
|
|
6
|
-
const {
|
|
7
|
-
children,
|
|
8
|
-
...context
|
|
9
|
-
} = props;
|
|
10
|
-
const value = React.useMemo(() => context, Object.values(context));
|
|
11
|
-
return /* @__PURE__ */jsx(Context.Provider, {
|
|
12
|
-
value,
|
|
13
|
-
children
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function useContext(consumerName) {
|
|
17
|
-
const context = React.useContext(Context);
|
|
18
|
-
if (context) return context;
|
|
19
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
20
|
-
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
21
|
-
}
|
|
22
|
-
return [Provider, useContext];
|
|
23
|
-
}
|
|
24
|
-
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
25
|
-
let defaultContexts = [];
|
|
26
|
-
function createContext2(rootComponentName, defaultContext) {
|
|
27
|
-
const BaseContext = React.createContext(defaultContext);
|
|
28
|
-
const index = defaultContexts.length;
|
|
29
|
-
defaultContexts = [...defaultContexts, defaultContext];
|
|
30
|
-
function Provider(props) {
|
|
31
|
-
const {
|
|
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
|
-
return /* @__PURE__ */jsx(Context.Provider, {
|
|
39
|
-
value,
|
|
40
|
-
children
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function useContext(consumerName, scope, options) {
|
|
44
|
-
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
45
|
-
const context = React.useContext(Context);
|
|
46
|
-
if (context) return context;
|
|
47
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
48
|
-
const missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
49
|
-
if (options?.fallback) {
|
|
50
|
-
if (options?.warn !== false) {
|
|
51
|
-
console.warn(missingContextMessage);
|
|
52
|
-
}
|
|
53
|
-
return options.fallback;
|
|
54
|
-
}
|
|
55
|
-
throw new Error(missingContextMessage);
|
|
56
|
-
}
|
|
57
|
-
return [Provider, useContext];
|
|
58
|
-
}
|
|
59
|
-
const createScope = () => {
|
|
60
|
-
const scopeContexts = defaultContexts.map(defaultContext => {
|
|
61
|
-
return React.createContext(defaultContext);
|
|
62
|
-
});
|
|
63
|
-
return function useScope(scope) {
|
|
64
|
-
const contexts = scope?.[scopeName] || scopeContexts;
|
|
65
|
-
return React.useMemo(() => ({
|
|
66
|
-
[`__scope${scopeName}`]: {
|
|
67
|
-
...scope,
|
|
68
|
-
[scopeName]: contexts
|
|
69
|
-
}
|
|
70
|
-
}), [scope, contexts]);
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
createScope.scopeName = scopeName;
|
|
74
|
-
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
75
|
-
}
|
|
76
|
-
function composeContextScopes(...scopes) {
|
|
77
|
-
const baseScope = scopes[0];
|
|
78
|
-
if (scopes.length === 1) return baseScope;
|
|
79
|
-
const createScope = () => {
|
|
80
|
-
const scopeHooks = scopes.map(createScope2 => ({
|
|
81
|
-
useScope: createScope2(),
|
|
82
|
-
scopeName: createScope2.scopeName
|
|
83
|
-
}));
|
|
84
|
-
return function useComposedScopes(overrideScopes) {
|
|
85
|
-
const nextScopes = scopeHooks.reduce((nextScopes2, {
|
|
86
|
-
useScope,
|
|
87
|
-
scopeName
|
|
88
|
-
}) => {
|
|
89
|
-
const scopeProps = useScope(overrideScopes);
|
|
90
|
-
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
91
|
-
return {
|
|
92
|
-
...nextScopes2,
|
|
93
|
-
...currentScope
|
|
94
|
-
};
|
|
95
|
-
}, {});
|
|
96
|
-
return React.useMemo(() => ({
|
|
97
|
-
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
98
|
-
}), [nextScopes]);
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
createScope.scopeName = baseScope.scopeName;
|
|
102
|
-
return createScope;
|
|
103
|
-
}
|
|
104
|
-
export { createContext, createContextScope };
|
|
105
|
-
//# sourceMappingURL=create-context.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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","BaseContext","index","length","scope","options","missingContextMessage","fallback","warn","console","createScope","scopeContexts","map","useScope","contexts","composeContextScopes","scopes","baseScope","scopeHooks","useComposedScopes","overrideScopes","nextScopes","reduce","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;IAC5E,MAAMN,OAAA,GAAUT,KAAA,CAAMc,UAAA,CAAWT,OAAO;IACxC,IAAII,OAAA,EAAS,OAAOA,OAAA;IACpB,IAAIL,cAAA,KAAmB,QAAW,OAAOA,cAAA;IAEzC,MAAM,IAAIY,KAAA,CAAM,KAAKD,YAAY,4BAA4BZ,iBAAiB,IAAI;EACpF;EAEA,OAAO,CAACG,QAAA,EAAUQ,UAAU;AAC9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;UAAE,GAAGuB,WAAA;UAAY,GAAGG;QAAa;MAC1C,GAAG,CAAC,CAAC;MAEL,OAAO5C,KAAA,CAAMW,OAAA,CACX,OAAO;QAAE,CAAC,UAAU0B,SAAA,CAAUnB,SAAS,EAAE,GAAGuB;MAAW,IACvD,CAACA,UAAU,CACb;IACF;EACF;EAEAX,WAAA,CAAYZ,SAAA,GAAYmB,SAAA,CAAUnB,SAAA;EAClC,OAAOY,WAAA;AACT","ignoreList":[]}
|
|
@@ -1,122 +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
|
-
var 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, useContext];
|
|
25
|
-
}
|
|
26
|
-
function createContextScope(scopeName) {
|
|
27
|
-
var createContextScopeDeps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
28
|
-
var defaultContexts = [];
|
|
29
|
-
function createContext2(rootComponentName, defaultContext) {
|
|
30
|
-
var BaseContext = /* @__PURE__ */React.createContext(defaultContext);
|
|
31
|
-
var index = defaultContexts.length;
|
|
32
|
-
defaultContexts = [...defaultContexts, defaultContext];
|
|
33
|
-
function Provider(props) {
|
|
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
|
-
return /* @__PURE__ */_jsx(Context.Provider, {
|
|
45
|
-
value,
|
|
46
|
-
children
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function useContext(consumerName, scope, options) {
|
|
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
|
-
if (context) return context;
|
|
54
|
-
if (defaultContext !== void 0) return defaultContext;
|
|
55
|
-
var missingContextMessage = `\`${consumerName}\` must be used within \`${rootComponentName}\``;
|
|
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
|
-
}
|
|
62
|
-
throw new Error(missingContextMessage);
|
|
63
|
-
}
|
|
64
|
-
return [Provider, useContext];
|
|
65
|
-
}
|
|
66
|
-
var createScope = function () {
|
|
67
|
-
var scopeContexts = defaultContexts.map(function (defaultContext) {
|
|
68
|
-
return /* @__PURE__ */React.createContext(defaultContext);
|
|
69
|
-
});
|
|
70
|
-
return function useScope(scope) {
|
|
71
|
-
var contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
|
|
72
|
-
return React.useMemo(function () {
|
|
73
|
-
return {
|
|
74
|
-
[`__scope${scopeName}`]: {
|
|
75
|
-
...scope,
|
|
76
|
-
[scopeName]: contexts
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}, [scope, contexts]);
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
createScope.scopeName = scopeName;
|
|
83
|
-
return [createContext2, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
84
|
-
}
|
|
85
|
-
function composeContextScopes() {
|
|
86
|
-
for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
87
|
-
scopes[_key] = arguments[_key];
|
|
88
|
-
}
|
|
89
|
-
var baseScope = scopes[0];
|
|
90
|
-
if (scopes.length === 1) return baseScope;
|
|
91
|
-
var createScope = function () {
|
|
92
|
-
var scopeHooks = scopes.map(function (createScope2) {
|
|
93
|
-
return {
|
|
94
|
-
useScope: createScope2(),
|
|
95
|
-
scopeName: createScope2.scopeName
|
|
96
|
-
};
|
|
97
|
-
});
|
|
98
|
-
return function useComposedScopes(overrideScopes) {
|
|
99
|
-
var nextScopes = scopeHooks.reduce(function (nextScopes2, param) {
|
|
100
|
-
var {
|
|
101
|
-
useScope,
|
|
102
|
-
scopeName
|
|
103
|
-
} = param;
|
|
104
|
-
var scopeProps = useScope(overrideScopes);
|
|
105
|
-
var currentScope = scopeProps[`__scope${scopeName}`];
|
|
106
|
-
return {
|
|
107
|
-
...nextScopes2,
|
|
108
|
-
...currentScope
|
|
109
|
-
};
|
|
110
|
-
}, {});
|
|
111
|
-
return React.useMemo(function () {
|
|
112
|
-
return {
|
|
113
|
-
[`__scope${baseScope.scopeName}`]: nextScopes
|
|
114
|
-
};
|
|
115
|
-
}, [nextScopes]);
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
|
-
createScope.scopeName = baseScope.scopeName;
|
|
119
|
-
return createScope;
|
|
120
|
-
}
|
|
121
|
-
export { createContext, createContextScope };
|
|
122
|
-
//# sourceMappingURL=create-context.native.js.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","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":[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;MAAMC,QAAE;MAAA,GAAUC;IAAG,IAAQF,KAAI;IAGjC,IAAAG,KAAM,GAAAT,KAAQ,CAAAU,OAAM,aAAc;MAClC,OAAOF,OAAA;IACT,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,OAAQ,GAAAR,KAAU,CAAAa,UAAU,CAAAT,OAAA;IAC9B,IAAAI,OAAA,SAAAA,OAAA;IAeO,IAAAL,cAAS,UACd,UACAA,cAAA;IAuBA,MAAI,IAAAY,KAAA,MAA0BD,YAAA,4BAAAZ,iBAAA;EAM9B;EAIE,QACAG,QAAM,EACNQ,UAAA,CAEA;AAME;AACA,SAAAG,kBAAgBA,CAAAC,SAAQ,EAAS;EAGjC,IAAAC,sBAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAAA,IAAAE,eACZ;EAAA,SACNC,cAAcA,CAAApB,iBAAO,EAAAC,cAAA;IAAA,IACvBoB,WAAA,kBAAAvB,KAAA,CAAAC,aAAA,C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F,OAAAD,OAAA,CAAAE,QAAA;MACF;MAEA,UAAYd,KAAA,CAAAa,qBAAY;IAExB;IACE,QACAvB,QAAA,EACFQ,UAAA,CACF;EAMA;EACE,IAAAmB,WAAM,GAAY,SAAAA,CAAA,EAAQ;IAC1B,IAAIC,aAAO,GAAWZ,eAAU,CAAAa,GAAA,WAAA/B,cAAA;MAEhC,OAAM,eAAiCH,KAAA,CAAAC,aAAA,CAAAE,cAAA;IACrC;IAAgD,OAC9C,SAAUgC,QAAAH,CAAYN,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/dist/esm/index.mjs
DELETED
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/esm/index.native.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|