You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
833 B
JavaScript
37 lines
833 B
JavaScript
'use strict';
|
|
|
|
const findAlignment = require("../tags/find-alignment");
|
|
|
|
module.exports = function componentsToLines(items) {
|
|
let currentLineItems = [];
|
|
let lines = [];
|
|
let lastAlignment = null;
|
|
|
|
function closeLine() {
|
|
lines.push(currentLineItems);
|
|
currentLineItems = [];
|
|
lastAlignment = null;
|
|
}
|
|
|
|
items.forEach((item) => {
|
|
if (item.type === "newline") {
|
|
closeLine();
|
|
} else {
|
|
let itemAlignment = findAlignment(item);
|
|
|
|
if (itemAlignment !== lastAlignment && currentLineItems.length > 0) {
|
|
/* We consider an alignment tag to be a 'block-level' element, therefore if it's
|
|
* encountered as anything but the first element, it automatically results in a
|
|
* new line. */
|
|
closeLine();
|
|
}
|
|
|
|
currentLineItems.push(item);
|
|
lastAlignment = itemAlignment;
|
|
}
|
|
});
|
|
|
|
closeLine();
|
|
return lines;
|
|
};
|