-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(roadiz): add RoadizBlockFactory component
- Loading branch information
1 parent
b662643
commit 5ef8434
Showing
2 changed files
with
31 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { FunctionalComponent, VNodeChild } from 'vue' | ||
import { h, resolveDynamicComponent, resolveComponent } from 'vue' | ||
import type { RoadizWalker } from '@roadiz/types' | ||
|
||
export interface RoadizBlockFactoryProps { | ||
prefix?: string | ||
blocks: RoadizWalker[] | ||
[key: string]: unknown | ||
} | ||
|
||
const isComponent = (component: string): boolean => { | ||
return typeof resolveDynamicComponent(component) !== 'string' | ||
} | ||
|
||
const RoadizBlockFactory: FunctionalComponent<RoadizBlockFactoryProps> = ({ blocks, prefix }, context): VNodeChild => { | ||
const blocksWithComponent = blocks.filter((block) => { | ||
const componentName = prefix ? prefix + block.item['@type'] : block.item['@type'] | ||
return isComponent(componentName) | ||
}) | ||
return blocksWithComponent.map((block, index, blocks) => { | ||
const componentName = prefix ? prefix + block.item['@type'] : block.item['@type'] | ||
return h(resolveComponent(componentName), { | ||
walker: block, | ||
index, | ||
numBlocks: blocks.length, | ||
...context.attrs, | ||
}) | ||
}) | ||
} | ||
|
||
export default RoadizBlockFactory |
This file was deleted.
Oops, something went wrong.