mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 04:33:47 +08:00
22 lines
702 B
JavaScript
22 lines
702 B
JavaScript
import Separator from 'flarum/components/separator';
|
|
|
|
function isSeparator(item) {
|
|
return item && item.component === Separator;
|
|
}
|
|
|
|
export default function listItems(array, noWrap) {
|
|
// Remove duplicate/unnecessary separators
|
|
var prevItem;
|
|
var newArray = [];
|
|
array.forEach(function(item, i) {
|
|
if ((!prevItem || isSeparator(prevItem) || i === array.length - 1) && isSeparator(item)) {
|
|
|
|
} else {
|
|
prevItem = item;
|
|
newArray.push(item);
|
|
}
|
|
});
|
|
|
|
return newArray.map(item => [(noWrap && !isSeparator(item)) ? item : m('li', {className: item.wrapperClass || (item.props && item.props.wrapperClass) || (item.component && item.component.wrapperClass) || ''}, item), ' ']);
|
|
};
|