Skip to content

Commit 5ef8434

Browse files
committed
feat(roadiz): add RoadizBlockFactory component
1 parent b662643 commit 5ef8434

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

components/RoadizBlockFactory.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { FunctionalComponent, VNodeChild } from 'vue'
2+
import { h, resolveDynamicComponent, resolveComponent } from 'vue'
3+
import type { RoadizWalker } from '@roadiz/types'
4+
5+
export interface RoadizBlockFactoryProps {
6+
prefix?: string
7+
blocks: RoadizWalker[]
8+
[key: string]: unknown
9+
}
10+
11+
const isComponent = (component: string): boolean => {
12+
return typeof resolveDynamicComponent(component) !== 'string'
13+
}
14+
15+
const RoadizBlockFactory: FunctionalComponent<RoadizBlockFactoryProps> = ({ blocks, prefix }, context): VNodeChild => {
16+
const blocksWithComponent = blocks.filter((block) => {
17+
const componentName = prefix ? prefix + block.item['@type'] : block.item['@type']
18+
return isComponent(componentName)
19+
})
20+
return blocksWithComponent.map((block, index, blocks) => {
21+
const componentName = prefix ? prefix + block.item['@type'] : block.item['@type']
22+
return h(resolveComponent(componentName), {
23+
walker: block,
24+
index,
25+
numBlocks: blocks.length,
26+
...context.attrs,
27+
})
28+
})
29+
}
30+
31+
export default RoadizBlockFactory

components/VRequiredMark.vue

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)