一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
43 行
1.0 KiB
TypeScript
43 行
1.0 KiB
TypeScript
import { LayoutItem, Size } from './types';
|
|
import { produce } from 'immer';
|
|
import iterateItems from './iterateItems';
|
|
import validateLayout from './validateLayout';
|
|
|
|
export function saveLayout(layout: LayoutItem): Partial<LayoutItem> {
|
|
const propertyWhiteList = [
|
|
'visible',
|
|
'width',
|
|
'height',
|
|
'children',
|
|
'key',
|
|
'context',
|
|
'flexible',
|
|
];
|
|
|
|
return produce(layout, (draft: LayoutItem) => {
|
|
delete draft.width;
|
|
delete draft.height;
|
|
iterateItems(draft, (_itemIndex: number, item: LayoutItem, _parent: LayoutItem) => {
|
|
for (const k of Object.keys(item)) {
|
|
if (!propertyWhiteList.includes(k)) delete (item as unknown as Record<string, unknown>)[k];
|
|
}
|
|
return true;
|
|
});
|
|
});
|
|
}
|
|
|
|
export function loadLayout(layout: Partial<LayoutItem> | null, defaultLayout: LayoutItem, rootSize: Size): LayoutItem {
|
|
let output: LayoutItem = null;
|
|
|
|
if (layout) {
|
|
output = { ...layout } as LayoutItem;
|
|
} else {
|
|
output = { ...defaultLayout };
|
|
}
|
|
|
|
output.width = rootSize.width;
|
|
output.height = rootSize.height;
|
|
|
|
return validateLayout(output);
|
|
}
|