Treat single content items as blocks
This commit is contained in:
parent
2905486c2f
commit
251c05abad
|
|
@ -102,32 +102,43 @@
|
||||||
return this.contentBlock.mine && !this.contentBlock.indent;
|
return this.contentBlock.mine && !this.contentBlock.indent;
|
||||||
},
|
},
|
||||||
contentBlocksWithContentLists() {
|
contentBlocksWithContentLists() {
|
||||||
/* collects all conent_list_items in content_lists
|
/*
|
||||||
|
collects all conent_list_items in content_lists:
|
||||||
{
|
{
|
||||||
text_block,
|
text_block,
|
||||||
content_list_item,
|
content_list_item: [contents...],
|
||||||
contentlist_item,
|
contentlist_item: [contents...],
|
||||||
text_block
|
text_block
|
||||||
} becomes
|
} becomes
|
||||||
{
|
{
|
||||||
text_block,
|
text_block,
|
||||||
content_list: [content_list_item, content_list_item],
|
content_list: [content_list_item: [contents...], content_list_item: [contents...]],
|
||||||
text_block
|
text_block
|
||||||
}
|
}
|
||||||
|
if there's only a single content_list_item it should not be displayed as list like so
|
||||||
|
{
|
||||||
|
text_block,
|
||||||
|
content_list_item: [text_block, image_block],
|
||||||
|
} becomes
|
||||||
|
{
|
||||||
|
text_block,
|
||||||
|
text_block,
|
||||||
|
image_block
|
||||||
|
}
|
||||||
*/
|
*/
|
||||||
let contentList = [];
|
let contentList = [];
|
||||||
let newContent = this.contentBlock.contents.reduce((newContents, content, index) => {
|
let newContent = this.contentBlock.contents.reduce((newContents, content, index) => {
|
||||||
// collect content_list_items
|
// collect content_list_items
|
||||||
if (content.type === 'content_list_item') {
|
if (content.type === 'content_list_item') {
|
||||||
contentList = [...contentList, content]
|
contentList = [...contentList, content]
|
||||||
if (index === this.contentBlock.contents.length - 1) {
|
if (index === this.contentBlock.contents.length - 1) { // content is last element of contents array
|
||||||
return [...newContents, this.createContentList(contentList)];
|
return [...newContents, ...this.createContentListOrBlocks(contentList)];
|
||||||
}
|
}
|
||||||
return newContents
|
return newContents
|
||||||
} else {
|
} else {
|
||||||
// handle all other items and reset current content_list if necessary
|
// handle all other items and reset current content_list if necessary
|
||||||
if (contentList.length !== 0) {
|
if (contentList.length !== 0) {
|
||||||
newContents = [...newContents, this.createContentList(contentList), content];
|
newContents = [...newContents, ...this.createContentListOrBlocks(contentList), content];
|
||||||
contentList = [];
|
contentList = [];
|
||||||
return newContents;
|
return newContents;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -135,6 +146,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return Object.assign({}, this.contentBlock, {
|
return Object.assign({}, this.contentBlock, {
|
||||||
contents: newContent
|
contents: newContent
|
||||||
});
|
});
|
||||||
|
|
@ -171,12 +183,17 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createContentList(contentList) {
|
createContentListOrBlocks(contentList) {
|
||||||
return {
|
// if list contains only one item, return blocks
|
||||||
|
if (contentList.length === 1) {
|
||||||
|
return contentList[0].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [{
|
||||||
type: 'content_list',
|
type: 'content_list',
|
||||||
contents: contentList,
|
contents: contentList,
|
||||||
id: contentList[0].id
|
id: contentList[0].id
|
||||||
};
|
}];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,10 @@
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
contentBlocks() {
|
contentBlocks() {
|
||||||
const indent = this.contents.length > 1;
|
|
||||||
return this.contents.map(contentBlock => {
|
return this.contents.map(contentBlock => {
|
||||||
return Object.assign({}, contentBlock, {
|
return Object.assign({}, contentBlock, {
|
||||||
contents: [...contentBlock.value],
|
contents: [...contentBlock.value],
|
||||||
indent
|
indent: true
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue