1- <template >
2- <div class =" layout_builder" >
3- <template v-for =" (section , index ) of sections " >
4- <component
5- :is =" componentIs(section.layout_id)"
6- v-if =" componentIs(section.layout_id) !== 'div'"
7- :key =" index"
8- :section =" section"
9- >
10- <template
11- v-for =" component of Object .values (section .components )"
12- #[component .uuid ]
13- >
14- <component
15- :is =" componentIs(component.configuration.id)"
16- v-if =" componentIs(component.configuration.id) !== 'div'"
17- :key =" component.uuid"
18- :component =" component"
19- :entity =" entity"
20- />
21-
22- <DruxtDebug
23- v-else
24- :key =" component .uuid "
25- :summary =" ` ${componentName (component .configuration .id )} missing ` "
26- >
27- <pre ><code >{{ JSON.stringify(component, null, ' ') }}</code ></pre >
28- </DruxtDebug >
29- </template >
30- </component >
31-
32- <DruxtDebug
33- v-else
34- :key =" index "
35- :summary =" ` ${componentName (section .layout_id )} missing ` "
36- >
37- <pre ><code >{{ JSON.stringify(section, null, ' ') }}</code ></pre >
38- </DruxtDebug >
39- </template >
40- </div >
41- </template >
42-
431<script >
44- import { pascalCase , upperFirst } from ' scule'
2+ import DruxtModule from ' druxt/dist/components/DruxtModule.vue'
3+ // import { pascalCase, upperFirst } from 'scule'
454
465export default {
476 name: ' DruxtLayoutBuilder' ,
487
8+ extends: DruxtModule,
9+
4910 props: {
5011 entity: {
5112 type: Object ,
@@ -57,15 +18,43 @@ export default {
5718 sections : ({ entity }) => entity .attributes .layout_builder__layout
5819 },
5920
60- methods: {
61- componentIs (id ) {
62- const name = this .componentName (id)
63- return this .$nuxt .$options .components [name] ? name : ' div'
64- },
65-
66- componentName (id ) {
67- return ` DruxtLayoutBuilder${ pascalCase (id .split (' :' ).map ((s ) => upperFirst (s)).join (' ' ))} `
68- },
21+ druxt: {
22+ /**
23+ * @param {object} context - The module component ViewModel.
24+ * @returns {ComponentOptions}
25+ */
26+ componentOptions : ({ entity }) => [
27+ [entity .type ],
28+ [' default' ],
29+ ],
30+
31+ /**
32+ * Provides propsData for the DruxtWrapper.
33+ *
34+ * @param {object} context - The module component ViewModel.
35+ * @returns {PropsData}
36+ */
37+ propsData : ({ entity, sections }) => ({ entity, sections }),
38+
39+ /**
40+ * @return {ScopedSlots} The Scoped slots object.
41+ */
42+ slots (h ) {
43+ const slots = {}
44+
45+ this .sections .forEach ((section , index ) => {
46+ slots[` section-${ index} ` ] = () => h (' DruxtLayoutBuilderSection' , {
47+ props: {
48+ entity: this .entity ,
49+ section,
50+ }
51+ })
52+ })
53+
54+ slots .default = () => h (' div' , this .sections .map ((section , index ) => slots[` section-${ index} ` ]()))
55+
56+ return slots
57+ }
6958 }
7059}
7160 </script >
0 commit comments