1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/app-desktop/gui/ResizableLayout/utils/removeItem.ts

19 lines
574 B
TypeScript
Raw Normal View History

import produce from 'immer';
import iterateItems from './iterateItems';
import { LayoutItem } from './types';
import validateLayout from './validateLayout';
export default function(layout: LayoutItem, itemKey: string): LayoutItem {
const output = produce(layout, (layoutDraft: LayoutItem) => {
iterateItems(layoutDraft, (itemIndex: number, item: LayoutItem, parent: LayoutItem) => {
if (item.key === itemKey) {
parent.children.splice(itemIndex, 1);
return false;
}
return true;
});
});
return output !== layout ? validateLayout(output) : layout;
}