This repository has been archived by the owner on Dec 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ node_modules/ | |
dist/ | ||
stats.html | ||
storybook-static | ||
lib | ||
|
||
# yarn 3 | ||
.pnp.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
news | ||
lib | ||
towncrier.toml | ||
.towncrier | ||
.storybook | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"plone": { | ||
"packages": { | ||
"@plone/types/*": "/packages/types/*" | ||
}, | ||
"url": "git@github.com:plone/volto.git", | ||
"https": "https://github.com/plone/volto.git", | ||
"branch": "plone/types" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const DefaultBlockView = () => { | ||
return <>This block has no view assigned</>; | ||
}; | ||
|
||
export default DefaultBlockView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Fragment } from 'react'; | ||
// import { defineMessages, useIntl } from 'react-intl'; | ||
|
||
import { map } from 'lodash'; | ||
import { hasBlocksData } from '../../helpers/blocks'; | ||
import DefaultBlockView from './DefaultBlockView'; | ||
import type { GetContentResponse } from '@plone/types/content/get'; | ||
import type { BlocksConfig } from '@plone/types/config/Blocks'; | ||
import type { Location } from 'history'; | ||
|
||
type RenderBlocksProps = { | ||
content: GetContentResponse; | ||
blocksConfig: BlocksConfig; | ||
as: React.ElementType; | ||
location: Location; | ||
metadata?: GetContentResponse; | ||
}; | ||
|
||
const RenderBlocks = (props: RenderBlocksProps) => { | ||
const { blocksConfig, content, location, metadata } = props; | ||
const CustomTag = props.as || Fragment; | ||
|
||
return hasBlocksData(content) ? ( | ||
<CustomTag> | ||
{map(content.blocks_layout.items, (block) => { | ||
const blockData = content.blocks?.[block]; | ||
const blockType = blockData?.['@type']; | ||
const Block = blocksConfig[blockType]?.view || DefaultBlockView; | ||
|
||
return Block ? ( | ||
<Block | ||
id={block} | ||
metadata={metadata} | ||
properties={content} | ||
data={blockData} | ||
path={location?.pathname || ''} | ||
blocksConfig={blocksConfig} | ||
/> | ||
) : blockData ? ( | ||
<div key={block}>Unknown block found: {blockType}</div> | ||
) : ( | ||
<div key={block}>Invalid Block</div> | ||
); | ||
})} | ||
</CustomTag> | ||
) : ( | ||
'' | ||
); | ||
}; | ||
|
||
export default RenderBlocks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { GetContentResponse } from '@plone/types/content/get'; | ||
import { find, keys, endsWith } from 'lodash'; | ||
|
||
export function hasBlocksData(content: GetContentResponse) { | ||
return ( | ||
find( | ||
keys(content), | ||
(key) => key !== 'volto.blocks' && endsWith(key, 'blocks'), | ||
) !== undefined | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters