Add continuos numbering for content lists
This commit is contained in:
parent
75ba289100
commit
117782a337
|
|
@ -122,7 +122,7 @@
|
|||
},
|
||||
contentBlocksWithContentLists() {
|
||||
/*
|
||||
collects all conent_list_items in content_lists:
|
||||
collects all content_list_items in content_lists:
|
||||
{
|
||||
text_block,
|
||||
content_list_item: [contents...],
|
||||
|
|
@ -146,18 +146,21 @@
|
|||
}
|
||||
*/
|
||||
let contentList = [];
|
||||
let startingIndex = 0;
|
||||
let newContent = this.contentBlock.contents.reduce((newContents, content, index) => {
|
||||
// collect content_list_items
|
||||
if (content.type === 'content_list_item') {
|
||||
contentList = [...contentList, content]
|
||||
if (index === this.contentBlock.contents.length - 1) { // content is last element of contents array
|
||||
return [...newContents, ...this.createContentListOrBlocks(contentList)];
|
||||
startingIndex = this.updateStartingIndex(startingIndex, contentList);
|
||||
return [...newContents, ...this.createContentListOrBlocks(contentList, startingIndex)];
|
||||
}
|
||||
return newContents
|
||||
return newContents;
|
||||
} else {
|
||||
// handle all other items and reset current content_list if necessary
|
||||
if (contentList.length !== 0) {
|
||||
newContents = [...newContents, ...this.createContentListOrBlocks(contentList), content];
|
||||
newContents = [...newContents, ...this.createContentListOrBlocks(contentList, startingIndex), content];
|
||||
startingIndex = this.updateStartingIndex(startingIndex, contentList);
|
||||
contentList = [];
|
||||
return newContents;
|
||||
} else {
|
||||
|
|
@ -165,9 +168,10 @@
|
|||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
let some = this.removeSingleContentListItem(newContent, startingIndex);
|
||||
console.log(some)
|
||||
return Object.assign({}, this.contentBlock, {
|
||||
contents: newContent
|
||||
contents: some
|
||||
});
|
||||
},
|
||||
schoolClass() {
|
||||
|
|
@ -209,18 +213,29 @@
|
|||
}
|
||||
});
|
||||
},
|
||||
createContentListOrBlocks(contentList) {
|
||||
// if list contains only one item, return blocks
|
||||
if (contentList.length === 1) {
|
||||
return contentList[0].value;
|
||||
}
|
||||
|
||||
createContentListOrBlocks(contentList, startingIndex) {
|
||||
return [{
|
||||
type: 'content_list',
|
||||
contents: contentList,
|
||||
id: contentList[0].id
|
||||
id: contentList[0].id,
|
||||
startingIndex
|
||||
}];
|
||||
},
|
||||
updateStartingIndex(startingIndex, contentList) {
|
||||
return contentList.length > 1 ? startingIndex + contentList.length : startingIndex;
|
||||
},
|
||||
removeSingleContentListItem(content, index) {
|
||||
// just handle the case where we have one contentlistItem ( no index like "a)"" will be shown)
|
||||
if (index > 0) {
|
||||
return content;
|
||||
};
|
||||
|
||||
let contentListIndex = content.findIndex(contentItem => contentItem.type === 'content_list');
|
||||
if (contentListIndex < 0) {
|
||||
return content;
|
||||
}
|
||||
return [...content.slice(0, contentListIndex), ...content[contentListIndex].contents[0].value, ...content.slice(contentListIndex + 1)];
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<div class="content-list-block__container">
|
||||
<div class="content-list-wrapper">
|
||||
<ol class="content-list">
|
||||
<ol class="content-list" :style="`counter-reset: list ${startingIndex}`">
|
||||
<li class="content-list__item contentlist-item" :key="contentBlock.id" v-for="contentBlock in contentBlocks">
|
||||
<content-block :contentBlock="contentBlock"></content-block>
|
||||
</li>
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
// import ContentBlock from '@/components/ContentBlock';
|
||||
|
||||
export default {
|
||||
props: ['contents', 'parent'],
|
||||
props: ['contents', 'parent', 'startingIndex'],
|
||||
name: 'content-block-list',
|
||||
|
||||
components: {
|
||||
|
|
@ -43,7 +43,6 @@
|
|||
.content-list-wrapper {
|
||||
.content-list {
|
||||
/* https://stackoverflow.com/questions/1632005/ordered-list-html-lower-alpha-with-right-parentheses */
|
||||
counter-reset: list;
|
||||
|
||||
&__item {
|
||||
list-style: none;
|
||||
|
|
|
|||
Loading…
Reference in New Issue