@arc-fusion/components
Advanced tools
Comparing version 3.0.0-beta.3 to 3.0.0-beta.4
{ | ||
"name": "@arc-fusion/components", | ||
"version": "3.0.0-beta.3", | ||
"version": "3.0.0-beta.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/components/index.js", |
@@ -34,18 +34,20 @@ 'use strict' | ||
const getTransformedContent = (getContent) => (config) => { | ||
const getTransformedContent = (getContent, globalContent) => (config) => { | ||
const source = config.sourceName || config.source || config.contentService | ||
if (!source && !config.inherit) { | ||
return { | ||
fetched: Promise.resolve() | ||
const content = (config.inherit) | ||
? { | ||
cached: globalContent, | ||
fetched: Promise.resolve(globalContent) | ||
} | ||
} | ||
: (source) | ||
? getContent({ | ||
source, | ||
query: config.query || config.contentConfigValues, | ||
filter: config.filter | ||
}) | ||
: { | ||
fetched: Promise.resolve() | ||
} | ||
const content = getContent({ | ||
inherit: config.inherit, | ||
source, | ||
query: config.query || config.contentConfigValues, | ||
filter: config.filter | ||
}) | ||
return (config.transform) | ||
@@ -91,3 +93,3 @@ ? { | ||
deployment: getDeploymentAppender(deployment), | ||
getContent: getTransformedContent(getContent), | ||
getContent: getTransformedContent(getContent, appContext.globalContent), | ||
tree | ||
@@ -125,3 +127,3 @@ } | ||
deployment: getDeploymentAppender(deployment), | ||
getContent: getTransformedContent(getContent) | ||
getContent: getTransformedContent(getContent, appContext.globalContent) | ||
} | ||
@@ -128,0 +130,0 @@ }, |
@@ -6,10 +6,7 @@ 'use strict' | ||
const contextHOC = require('./utils/context-hoc') | ||
const { useEditableContent } = require('./utils/local-edits') | ||
const withHOC = require('./utils/with-hoc') | ||
const { ComponentContext } = require('../contexts') | ||
const { getComponentName, isClient } = require('../utils') | ||
const { isClient } = require('../utils') | ||
function useContent (config) { | ||
@@ -32,3 +29,21 @@ const [ content, setContent ] = React.useState() | ||
const Content = contextHOC(useContent, 'Content') | ||
const Content = ({ children, render, ...props }) => { | ||
const content = useContent(props) | ||
const childArray = [].concat(render || children || []) | ||
return React.createElement( | ||
React.Fragment, | ||
{}, | ||
childArray.map((child, index) => | ||
React.createElement( | ||
child, | ||
{ | ||
key: index, | ||
...content | ||
} | ||
) | ||
) | ||
) | ||
} | ||
Content.propTypes = { | ||
@@ -42,4 +57,30 @@ inherit: PropTypes.bool, | ||
const withContent = withHOC(Content) | ||
const withContent = (Component) => { | ||
const WrappedComponent = (props) => { | ||
const content = useContent(props) | ||
return React.createElement( | ||
Component, | ||
{ | ||
...props, | ||
content | ||
} | ||
) | ||
} | ||
Object.assign( | ||
WrappedComponent, | ||
Component, | ||
{ | ||
displayName: `withContent(${getComponentName(Component)})`, | ||
propTypes: { | ||
...(Component.propTypes || {}), | ||
...Content.propTypes | ||
} | ||
} | ||
) | ||
return WrappedComponent | ||
} | ||
module.exports = Content | ||
@@ -46,0 +87,0 @@ module.exports.Content = Content |
@@ -6,6 +6,4 @@ 'use strict' | ||
const { AppContext, ComponentContext } = require('../contexts') | ||
const { getComponentName } = require('../utils') | ||
const contextHOC = require('./utils/context-hoc') | ||
const withHOC = require('./utils/with-hoc') | ||
function useComponentContext () { | ||
@@ -45,13 +43,70 @@ const { getContent, ...componentContext } = React.useContext(ComponentContext) | ||
const FusionContext = contextHOC(useFusionContext, 'FusionContext') | ||
const namedHooks = { | ||
App: () => useAppContext(), | ||
Component: () => useComponentContext(), | ||
Fusion: () => useFusionContext() | ||
} | ||
const Context = (useContext) => { | ||
const ContextComponent = ({ children, render, ...props }) => { | ||
const context = useContext() | ||
const childArray = [].concat(render || children || []) | ||
return React.createElement( | ||
React.Fragment, | ||
{}, | ||
childArray.map((child, index) => | ||
React.createElement( | ||
child, | ||
{ | ||
key: index, | ||
...props, | ||
...context | ||
} | ||
) | ||
) | ||
) | ||
} | ||
ContextComponent.displayName = `${useContext.name || ''}Context` | ||
return ContextComponent | ||
} | ||
const withContext = (useContext) => (Component) => { | ||
const WrappedComponent = (props) => { | ||
const context = useContext() | ||
return React.createElement( | ||
Component, | ||
{ | ||
...props, | ||
...context | ||
} | ||
) | ||
} | ||
Object.assign( | ||
WrappedComponent, | ||
Component, | ||
{ | ||
displayName: `with${useContext.name || ''}Context(${getComponentName(Component)})` | ||
} | ||
) | ||
return WrappedComponent | ||
} | ||
const FusionContext = Context(namedHooks.Fusion) | ||
module.exports = FusionContext | ||
module.exports.AppContext = contextHOC(useAppContext, 'AppContext') | ||
module.exports.ComponentContext = contextHOC(useComponentContext, 'ComponentContext') | ||
module.exports.FusionContext = contextHOC(useFusionContext) | ||
module.exports.AppContext = Context(namedHooks.App) | ||
module.exports.ComponentContext = Context(namedHooks.Component) | ||
module.exports.FusionContext = FusionContext | ||
module.exports.useAppContext = useAppContext | ||
module.exports.useComponentContext = useComponentContext | ||
module.exports.useFusionContext = useFusionContext | ||
module.exports.withAppContext = withHOC(module.exports.AppContext) | ||
module.exports.withComponentContext = withHOC(module.exports.ComponentContext) | ||
module.exports.withFusionContext = withHOC(module.exports.FusionContext) | ||
module.exports.withAppContext = withContext(namedHooks.App) | ||
module.exports.withComponentContext = withContext(namedHooks.Component) | ||
module.exports.withFusionContext = withContext(namedHooks.Fusion) |
@@ -11,3 +11,3 @@ 'use strict' | ||
const Tree = (props) => { | ||
const { getComponent, getContent } = React.useContext(AppContext) | ||
const { getComponent, getContent, globalContent } = React.useContext(AppContext) | ||
@@ -40,2 +40,3 @@ const componentCache = {} | ||
const { children, collection, localEdits, type } = node | ||
const applyComponentEdits = applyLocalEdits.bind(null, localEdits) | ||
@@ -49,4 +50,4 @@ const id = node.fingerprint || node.id || node._id | ||
return { | ||
cached: applyLocalEdits(localEdits, cached), | ||
fetched: fetched.then(applyLocalEdits.bind(null, localEdits)) | ||
cached: applyComponentEdits(cached), | ||
fetched: fetched.then(applyComponentEdits) | ||
} | ||
@@ -56,3 +57,3 @@ } | ||
let globalContent | ||
let editedGlobalContent | ||
@@ -67,6 +68,6 @@ return React.createElement( | ||
get globalContent () { | ||
if (!globalContent) { | ||
globalContent = getComponentContent({ inherit: true }) | ||
if (!editedGlobalContent) { | ||
editedGlobalContent = applyComponentEdits(globalContent) | ||
} | ||
return globalContent | ||
return editedGlobalContent | ||
} | ||
@@ -73,0 +74,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20598
700
17