Socket
Socket
Sign inDemoInstall

@radix-ui/react-context

Package Overview
Dependencies
Maintainers
6
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-context - npm Package Compare versions

Comparing version 0.1.2-rc.2 to 0.1.2-rc.3

151

dist/index.js

@@ -1,2 +0,151 @@

var e,t,n=(e={},t=require("react"),Object.keys(t).forEach((function(n){"default"!==n&&"__esModule"!==n&&Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[n]}})})),e);function o(...e){const t=e[0];if(1===e.length)return t;const o=()=>{const o=e.map((e=>({useScope:e(),scopeName:e.scopeName})));return function(e){const r=o.reduce(((t,{useScope:n,scopeName:o})=>({...t,...n(e)[`__scope${o}`]})),{});return n.useMemo((()=>({[`__scope${t.scopeName}`]:r})),[r])}};return o.scopeName=t.scopeName,o}exports.createContext=function(e,t){const o=/*#__PURE__*/n.createContext(t);function r(e){const{children:t,...r}=e,c=n.useMemo((()=>r),Object.values(r));/*#__PURE__*/return n.createElement(o.Provider,{value:c},t)}return r.displayName=e+"Provider",[r,function(r){const c=n.useContext(o);if(c)return c;if(void 0!==t)return t;throw new Error(`\`${r}\` must be used within \`${e}\``)}]},exports.createContextScope=function(e,t=[]){let r=[];const c=()=>{const t=r.map((e=>/*#__PURE__*/n.createContext(e)));return function(o){const r=(null==o?void 0:o[e])||t;return n.useMemo((()=>({[`__scope${e}`]:{...o,[e]:r}})),[o,r])}};return c.scopeName=e,[function(t,o){const c=/*#__PURE__*/n.createContext(o),u=r.length;function s(t){const{scope:o,children:r,...s}=t,i=(null==o?void 0:o[e][u])||c,a=n.useMemo((()=>s),Object.values(s));/*#__PURE__*/return n.createElement(i.Provider,{value:a},r)}return r=[...r,o],s.displayName=t+"Provider",[s,function(r,s){const i=(null==s?void 0:s[e][u])||c,a=n.useContext(i);if(a)return a;if(void 0!==o)return o;throw new Error(`\`${r}\` must be used within \`${t}\``)}]},o(c,...t)]};
var $4O1Ne$react = require("react");
function $parcel$exportWildcard(dest, source) {
Object.keys(source).forEach(function(key) {
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
return;
}
Object.defineProperty(dest, key, {
enumerable: true,
get: function get() {
return source[key];
}
});
});
return dest;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
var $dec3cc0142d4f286$exports = {};
$parcel$export($dec3cc0142d4f286$exports, "createContext", () => $dec3cc0142d4f286$export$fd42f52fd3ae1109);
$parcel$export($dec3cc0142d4f286$exports, "createContextScope", () => $dec3cc0142d4f286$export$50c7b4e9d9f19c1);
function $dec3cc0142d4f286$export$fd42f52fd3ae1109(rootComponentName, defaultContext) {
const Context = /*#__PURE__*/ $4O1Ne$react.createContext(defaultContext);
function Provider(props) {
const { children: children , ...context } = props; // Only re-memoize when prop values change
// eslint-disable-next-line react-hooks/exhaustive-deps
const value = $4O1Ne$react.useMemo(()=>context
, Object.values(context));
return /*#__PURE__*/ $4O1Ne$react.createElement(Context.Provider, {
value: value
}, children);
}
function useContext(consumerName) {
const context = $4O1Ne$react.useContext(Context);
if (context) return context;
if (defaultContext !== undefined) return defaultContext; // if a defaultContext wasn't specified, it's a required context.
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
}
Provider.displayName = rootComponentName + 'Provider';
return [
Provider,
useContext
];
}
/* -------------------------------------------------------------------------------------------------
* createContextScope
* -----------------------------------------------------------------------------------------------*/ function $dec3cc0142d4f286$export$50c7b4e9d9f19c1(scopeName, createContextScopeDeps = []) {
let defaultContexts = [];
/* -----------------------------------------------------------------------------------------------
* createContext
* ---------------------------------------------------------------------------------------------*/ function $dec3cc0142d4f286$export$fd42f52fd3ae1109(rootComponentName, defaultContext) {
const BaseContext = /*#__PURE__*/ $4O1Ne$react.createContext(defaultContext);
const index = defaultContexts.length;
defaultContexts = [
...defaultContexts,
defaultContext
];
function Provider(props) {
const { scope: scope , children: children , ...context } = props;
const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index]) || BaseContext; // Only re-memoize when prop values change
// eslint-disable-next-line react-hooks/exhaustive-deps
const value = $4O1Ne$react.useMemo(()=>context
, Object.values(context));
return /*#__PURE__*/ $4O1Ne$react.createElement(Context.Provider, {
value: value
}, children);
}
function useContext(consumerName, scope) {
const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index]) || BaseContext;
const context = $4O1Ne$react.useContext(Context);
if (context) return context;
if (defaultContext !== undefined) return defaultContext; // if a defaultContext wasn't specified, it's a required context.
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
}
Provider.displayName = rootComponentName + 'Provider';
return [
Provider,
useContext
];
}
/* -----------------------------------------------------------------------------------------------
* createScope
* ---------------------------------------------------------------------------------------------*/ const createScope = ()=>{
const scopeContexts = defaultContexts.map((defaultContext)=>{
return /*#__PURE__*/ $4O1Ne$react.createContext(defaultContext);
});
return function useScope(scope) {
const contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
return $4O1Ne$react.useMemo(()=>({
[`__scope${scopeName}`]: {
...scope,
[scopeName]: contexts
}
})
, [
scope,
contexts
]);
};
};
createScope.scopeName = scopeName;
return [
$dec3cc0142d4f286$export$fd42f52fd3ae1109,
$dec3cc0142d4f286$var$composeContextScopes(createScope, ...createContextScopeDeps)
];
}
/* -------------------------------------------------------------------------------------------------
* composeContextScopes
* -----------------------------------------------------------------------------------------------*/ function $dec3cc0142d4f286$var$composeContextScopes(...scopes) {
const baseScope = scopes[0];
if (scopes.length === 1) return baseScope;
const createScope1 = ()=>{
const scopeHooks = scopes.map((createScope)=>({
useScope: createScope(),
scopeName: createScope.scopeName
})
);
return function useComposedScopes(overrideScopes) {
const nextScopes1 = scopeHooks.reduce((nextScopes, { useScope: useScope , scopeName: scopeName })=>{
// We are calling a hook inside a callback which React warns against to avoid inconsistent
// renders, however, scoping doesn't have render side effects so we ignore the rule.
// eslint-disable-next-line react-hooks/rules-of-hooks
const scopeProps = useScope(overrideScopes);
const currentScope = scopeProps[`__scope${scopeName}`];
return {
...nextScopes,
...currentScope
};
}, {});
return $4O1Ne$react.useMemo(()=>({
[`__scope${baseScope.scopeName}`]: nextScopes1
})
, [
nextScopes1
]);
};
};
createScope1.scopeName = baseScope.scopeName;
return createScope1;
}
$parcel$exportWildcard(module.exports, $dec3cc0142d4f286$exports);
//# sourceMappingURL=index.js.map

@@ -1,2 +0,135 @@

import*as e from"react";export function createContext(t,n){const o=/*#__PURE__*/e.createContext(n);function r(t){const{children:n,...r}=t,c=e.useMemo((()=>r),Object.values(r));/*#__PURE__*/return e.createElement(o.Provider,{value:c},n)}return r.displayName=t+"Provider",[r,function(r){const c=e.useContext(o);if(c)return c;if(void 0!==n)return n;throw new Error(`\`${r}\` must be used within \`${t}\``)}]}export function createContextScope(n,o=[]){let r=[];const c=()=>{const t=r.map((t=>/*#__PURE__*/e.createContext(t)));return function(o){const r=(null==o?void 0:o[n])||t;return e.useMemo((()=>({[`__scope${n}`]:{...o,[n]:r}})),[o,r])}};return c.scopeName=n,[function(t,o){const c=/*#__PURE__*/e.createContext(o),u=r.length;function s(t){const{scope:o,children:r,...s}=t,i=(null==o?void 0:o[n][u])||c,a=e.useMemo((()=>s),Object.values(s));/*#__PURE__*/return e.createElement(i.Provider,{value:a},r)}return r=[...r,o],s.displayName=t+"Provider",[s,function(r,s){const i=(null==s?void 0:s[n][u])||c,a=e.useContext(i);if(a)return a;if(void 0!==o)return o;throw new Error(`\`${r}\` must be used within \`${t}\``)}]},t(c,...o)]}function t(...t){const n=t[0];if(1===t.length)return n;const o=()=>{const o=t.map((e=>({useScope:e(),scopeName:e.scopeName})));return function(t){const r=o.reduce(((e,{useScope:n,scopeName:o})=>({...e,...n(t)[`__scope${o}`]})),{});return e.useMemo((()=>({[`__scope${n.scopeName}`]:r})),[r])}};return o.scopeName=n.scopeName,o}
import {createContext as $3bkAK$createContext, useMemo as $3bkAK$useMemo, createElement as $3bkAK$createElement, useContext as $3bkAK$useContext} from "react";
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
var $c512c27ab02ef895$exports = {};
$parcel$export($c512c27ab02ef895$exports, "createContext", () => $c512c27ab02ef895$export$fd42f52fd3ae1109);
$parcel$export($c512c27ab02ef895$exports, "createContextScope", () => $c512c27ab02ef895$export$50c7b4e9d9f19c1);
function $c512c27ab02ef895$export$fd42f52fd3ae1109(rootComponentName, defaultContext) {
const Context = /*#__PURE__*/ $3bkAK$createContext(defaultContext);
function Provider(props) {
const { children: children , ...context } = props; // Only re-memoize when prop values change
// eslint-disable-next-line react-hooks/exhaustive-deps
const value = $3bkAK$useMemo(()=>context
, Object.values(context));
return /*#__PURE__*/ $3bkAK$createElement(Context.Provider, {
value: value
}, children);
}
function useContext(consumerName) {
const context = $3bkAK$useContext(Context);
if (context) return context;
if (defaultContext !== undefined) return defaultContext; // if a defaultContext wasn't specified, it's a required context.
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
}
Provider.displayName = rootComponentName + 'Provider';
return [
Provider,
useContext
];
}
/* -------------------------------------------------------------------------------------------------
* createContextScope
* -----------------------------------------------------------------------------------------------*/ function $c512c27ab02ef895$export$50c7b4e9d9f19c1(scopeName, createContextScopeDeps = []) {
let defaultContexts = [];
/* -----------------------------------------------------------------------------------------------
* createContext
* ---------------------------------------------------------------------------------------------*/ function $c512c27ab02ef895$export$fd42f52fd3ae1109(rootComponentName, defaultContext) {
const BaseContext = /*#__PURE__*/ $3bkAK$createContext(defaultContext);
const index = defaultContexts.length;
defaultContexts = [
...defaultContexts,
defaultContext
];
function Provider(props) {
const { scope: scope , children: children , ...context } = props;
const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index]) || BaseContext; // Only re-memoize when prop values change
// eslint-disable-next-line react-hooks/exhaustive-deps
const value = $3bkAK$useMemo(()=>context
, Object.values(context));
return /*#__PURE__*/ $3bkAK$createElement(Context.Provider, {
value: value
}, children);
}
function useContext(consumerName, scope) {
const Context = (scope === null || scope === void 0 ? void 0 : scope[scopeName][index]) || BaseContext;
const context = $3bkAK$useContext(Context);
if (context) return context;
if (defaultContext !== undefined) return defaultContext; // if a defaultContext wasn't specified, it's a required context.
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
}
Provider.displayName = rootComponentName + 'Provider';
return [
Provider,
useContext
];
}
/* -----------------------------------------------------------------------------------------------
* createScope
* ---------------------------------------------------------------------------------------------*/ const createScope = ()=>{
const scopeContexts = defaultContexts.map((defaultContext)=>{
return /*#__PURE__*/ $3bkAK$createContext(defaultContext);
});
return function useScope(scope) {
const contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
return $3bkAK$useMemo(()=>({
[`__scope${scopeName}`]: {
...scope,
[scopeName]: contexts
}
})
, [
scope,
contexts
]);
};
};
createScope.scopeName = scopeName;
return [
$c512c27ab02ef895$export$fd42f52fd3ae1109,
$c512c27ab02ef895$var$composeContextScopes(createScope, ...createContextScopeDeps)
];
}
/* -------------------------------------------------------------------------------------------------
* composeContextScopes
* -----------------------------------------------------------------------------------------------*/ function $c512c27ab02ef895$var$composeContextScopes(...scopes) {
const baseScope = scopes[0];
if (scopes.length === 1) return baseScope;
const createScope1 = ()=>{
const scopeHooks = scopes.map((createScope)=>({
useScope: createScope(),
scopeName: createScope.scopeName
})
);
return function useComposedScopes(overrideScopes) {
const nextScopes1 = scopeHooks.reduce((nextScopes, { useScope: useScope , scopeName: scopeName })=>{
// We are calling a hook inside a callback which React warns against to avoid inconsistent
// renders, however, scoping doesn't have render side effects so we ignore the rule.
// eslint-disable-next-line react-hooks/rules-of-hooks
const scopeProps = useScope(overrideScopes);
const currentScope = scopeProps[`__scope${scopeName}`];
return {
...nextScopes,
...currentScope
};
}, {});
return $3bkAK$useMemo(()=>({
[`__scope${baseScope.scopeName}`]: nextScopes1
})
, [
nextScopes1
]);
};
};
createScope1.scopeName = baseScope.scopeName;
return createScope1;
}
export {$c512c27ab02ef895$export$fd42f52fd3ae1109 as createContext, $c512c27ab02ef895$export$50c7b4e9d9f19c1 as createContextScope};
//# sourceMappingURL=index.module.js.map

2

package.json
{
"name": "@radix-ui/react-context",
"version": "0.1.2-rc.2",
"version": "0.1.2-rc.3",
"license": "MIT",

@@ -5,0 +5,0 @@ "source": "src/index.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc