@gravity-ui/uikit
Version:
Gravity UI base styling and components
36 lines (35 loc) • 1.11 kB
JavaScript
export function toItemList(items, separator, path = [], startIndex = 0) {
const updatedItems = [];
let addedGroup = false;
let index = startIndex;
for (const item of items) {
if (Array.isArray(item)) {
const groupItems = toItemList(item, separator, path, index);
if (updatedItems.length !== 0) {
updatedItems.push(separator);
}
updatedItems.push(...groupItems);
index += groupItems.length;
addedGroup = true;
}
else {
if (item.hidden) {
continue;
}
if (addedGroup) {
updatedItems.push(separator);
}
const updatedItem = {
...item,
path: [...path, index++],
};
if (item.items) {
updatedItem.items = toItemList(item.items, separator, updatedItem.path);
}
updatedItems.push(updatedItem);
addedGroup = false;
}
}
return updatedItems;
}
//# sourceMappingURL=toItemList.js.map