Refactor Editor and module functions (#15)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Moved all module functions to separate utils modules Replaced standard with standard with typescript Extracted UI elements to separate component Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/15
This commit is contained in:
parent
8e34d6b72a
commit
293af45144
26 changed files with 477 additions and 367 deletions
54
src/utils/saveload.ts
Normal file
54
src/utils/saveload.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { findContainerById, MakeIterator } from './itertools';
|
||||
import { IEditorState } from '../Editor';
|
||||
|
||||
/**
|
||||
* Revive the Editor state
|
||||
* by setting the containers references to their parent
|
||||
* @param editorState Editor state
|
||||
*/
|
||||
export function Revive(editorState: IEditorState): void {
|
||||
const history = editorState.history;
|
||||
for (const state of history) {
|
||||
if (state.MainContainer === null || state.MainContainer === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const it = MakeIterator(state.MainContainer);
|
||||
for (const container of it) {
|
||||
const parentId = container.properties.parentId;
|
||||
if (parentId === null) {
|
||||
container.parent = null;
|
||||
continue;
|
||||
}
|
||||
const parent = findContainerById(state.MainContainer, parentId);
|
||||
if (parent === undefined) {
|
||||
continue;
|
||||
}
|
||||
container.parent = parent;
|
||||
}
|
||||
|
||||
const selected = findContainerById(state.MainContainer, state.SelectedContainerId);
|
||||
if (selected === undefined) {
|
||||
state.SelectedContainer = null;
|
||||
continue;
|
||||
}
|
||||
state.SelectedContainer = selected;
|
||||
}
|
||||
}
|
||||
|
||||
export const getCircularReplacer = (): (key: any, value: object | null) => object | null | undefined => {
|
||||
const seen = new WeakSet();
|
||||
return (key: any, value: object | null) => {
|
||||
if (key === 'parent') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (seen.has(value)) {
|
||||
return;
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue