mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-27 10:32:58 +02:00
19 lines
574 B
TypeScript
19 lines
574 B
TypeScript
|
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;
|
||
|
}
|