2020-11-13 19:09:28 +02:00
|
|
|
import { LayoutItem, Size } from './types';
|
|
|
|
import produce from 'immer';
|
|
|
|
import iterateItems from './iterateItems';
|
|
|
|
import validateLayout from './validateLayout';
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-13 19:09:28 +02:00
|
|
|
export function saveLayout(layout: LayoutItem): any {
|
|
|
|
const propertyWhiteList = [
|
|
|
|
'visible',
|
|
|
|
'width',
|
|
|
|
'height',
|
|
|
|
'children',
|
|
|
|
'key',
|
|
|
|
'context',
|
|
|
|
];
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-13 19:09:28 +02:00
|
|
|
return produce(layout, (draft: any) => {
|
|
|
|
delete draft.width;
|
|
|
|
delete draft.height;
|
|
|
|
iterateItems(draft, (_itemIndex: number, item: LayoutItem, _parent: LayoutItem) => {
|
|
|
|
for (const k of Object.keys(item)) {
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-13 19:09:28 +02:00
|
|
|
if (!propertyWhiteList.includes(k)) delete (item as any)[k];
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2020-11-13 19:09:28 +02:00
|
|
|
export function loadLayout(layout: any, defaultLayout: LayoutItem, rootSize: Size): LayoutItem {
|
|
|
|
let output: LayoutItem = null;
|
|
|
|
|
|
|
|
if (layout) {
|
|
|
|
output = { ...layout };
|
|
|
|
} else {
|
|
|
|
output = { ...defaultLayout };
|
|
|
|
}
|
|
|
|
|
|
|
|
output.width = rootSize.width;
|
|
|
|
output.height = rootSize.height;
|
|
|
|
|
|
|
|
return validateLayout(output);
|
|
|
|
}
|