|
| 1 | +<template> |
| 2 | + <div class="sectionals"> |
| 3 | + |
| 4 | + <div |
| 5 | + v-for="section in sections" |
| 6 | + :key="section.id"> |
| 7 | + |
| 8 | + <section v-if="!section.hide" :id="section.slug" :class="['sectional', section.id]"> |
| 9 | + <!-- ============================================ [Section] Off Grid --> |
| 10 | + <div |
| 11 | + v-if="section.off_grid" |
| 12 | + :id="`${section.id}-background`" |
| 13 | + class="section-background"> |
| 14 | + |
| 15 | + <component |
| 16 | + :is="component.name" |
| 17 | + v-for="(component, i) in section.off_grid" |
| 18 | + :key="`${section.id}-background-${i}`" |
| 19 | + v-bind="component.props" /> |
| 20 | + |
| 21 | + </div> |
| 22 | + |
| 23 | + <!-- ================================================ [Section] Grid --> |
| 24 | + <div :class="[getGridClasses(section.grid), section.classNames]"> |
| 25 | + <template v-for="(block, blockId) in section"> |
| 26 | + <div |
| 27 | + v-if="blockAllowed(blockId)" |
| 28 | + :key="blockId" |
| 29 | + :class="[getColumnCount(block)]" |
| 30 | + :data-block-id="blockId" |
| 31 | + :data-push-left="getColumnPushCount(block, 'left')" |
| 32 | + :data-push-right="getColumnPushCount(block, 'right')"> |
| 33 | + <div class="column-content"> |
| 34 | + |
| 35 | + <!-- ======================================== [Block] Custom --> |
| 36 | + <template v-if="block.type === 'custom'"> |
| 37 | + <component |
| 38 | + :is="component.name" |
| 39 | + v-for="(component, componentKey) in block.customizations" |
| 40 | + :key="componentKey" |
| 41 | + v-bind="component.props" /> |
| 42 | + </template> |
| 43 | + |
| 44 | + <!-- ======================================= [Block] Dynamic --> |
| 45 | + <component |
| 46 | + :is="getComponentName(block)" |
| 47 | + v-else-if="block.type !== 'sectional'" |
| 48 | + v-bind="{ block }" /> |
| 49 | + |
| 50 | + <!-- ===================== Recursive Sectional/Block imports --> |
| 51 | + <!-- <BlockBuilder |
| 52 | + v-else |
| 53 | + :sections="block.sections" /> --> |
| 54 | + |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + </template> |
| 58 | + </div> |
| 59 | + </section> |
| 60 | + </div> |
| 61 | + |
| 62 | + </div> |
| 63 | +</template> |
| 64 | + |
| 65 | +<script> |
| 66 | +import TextBlock from '@/components/blocks/text-block' |
| 67 | +import ImageBlock from '@/components/blocks/image-block' |
| 68 | +import MarkdownBlock from '@/components/blocks/markdown-block' |
| 69 | +// import BlockBuilder from '@/components/blocks/block-builder' |
| 70 | +
|
| 71 | +export default { |
| 72 | + name: 'BlockBuilder', |
| 73 | +
|
| 74 | + components: { |
| 75 | + TextBlock, |
| 76 | + ImageBlock, |
| 77 | + // BlockBuilder, |
| 78 | + MarkdownBlock |
| 79 | + }, |
| 80 | +
|
| 81 | + props: { |
| 82 | + sections: { |
| 83 | + type: Object, |
| 84 | + required: true |
| 85 | + } |
| 86 | + }, |
| 87 | +
|
| 88 | + methods: { |
| 89 | + getGridClasses (blockGrid) { |
| 90 | + const classList = ['grid'] |
| 91 | + if (typeof blockGrid === 'object' && Array.isArray(blockGrid) && blockGrid.length > 0) { |
| 92 | + blockGrid.forEach(className => classList.push(`-${className}`)) |
| 93 | + } |
| 94 | + return classList.join('') |
| 95 | + }, |
| 96 | + blockAllowed (blockId) { |
| 97 | + return !['grid', 'classNames', 'off_grid', 'slug', 'hide', 'id'].includes(blockId) |
| 98 | + }, |
| 99 | + getColumnCount (block) { |
| 100 | + return block.cols.num |
| 101 | + }, |
| 102 | + getColumnPushCount (block, direction) { |
| 103 | + return block.cols.hasOwnProperty(`push_${direction}`) ? block.cols[`push_${direction}`] : undefined |
| 104 | + }, |
| 105 | + getComponentName (block) { |
| 106 | + const type = block.type |
| 107 | + let name = '' |
| 108 | + switch (type) { |
| 109 | + case 'text_block' : name = 'TextBlock'; break |
| 110 | + case 'image_block' : name = 'ImageBlock'; break |
| 111 | + case 'markdown_block': name = 'MarkdownBlock'; break |
| 112 | + case 'custom' : name = block.component; break |
| 113 | + } |
| 114 | + return name |
| 115 | + } |
| 116 | + } |
| 117 | +} |
| 118 | +</script> |
0 commit comments