Merged PR 164: Clear the leftover TODOs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- Remove nullable type from container.properties.parentId - Add Swal when trying to delete main container - Moved default editor state to default.ts - Moved default symbol model to default.ts
This commit is contained in:
parent
66ea3b1b64
commit
29625dce28
6 changed files with 81 additions and 48 deletions
|
@ -1,8 +1,11 @@
|
|||
import { XPositionReference } from '../Enums/XPositionReference';
|
||||
import { IAvailableContainer } from '../Interfaces/IAvailableContainer';
|
||||
import { IAvailableSymbol } from '../Interfaces/IAvailableSymbol';
|
||||
import { IConfiguration } from '../Interfaces/IConfiguration';
|
||||
import { IContainerModel } from '../Interfaces/IContainerModel';
|
||||
import { ContainerModel, IContainerModel } from '../Interfaces/IContainerModel';
|
||||
import IContainerProperties from '../Interfaces/IContainerProperties';
|
||||
import { IEditorState } from '../Interfaces/IEditorState';
|
||||
import { ISymbolModel } from '../Interfaces/ISymbolModel';
|
||||
|
||||
/// CONTAINER DEFAULTS ///
|
||||
|
||||
|
@ -29,6 +32,38 @@ export const ENABLE_SHORTCUTS = true;
|
|||
export const MAX_HISTORY = 200;
|
||||
export const APPLY_BEHAVIORS_ON_CHILDREN = true;
|
||||
|
||||
/**
|
||||
* Returns the default editor state given the configuration
|
||||
*/
|
||||
export const GetDefaultEditorState = (configuration: IConfiguration): IEditorState => {
|
||||
const mainContainer = new ContainerModel(
|
||||
null,
|
||||
{
|
||||
...DEFAULT_MAINCONTAINER_PROPS,
|
||||
width: Number(configuration.MainContainer.Width),
|
||||
height: Number(configuration.MainContainer.Height)
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
configuration,
|
||||
history: [
|
||||
{
|
||||
LastAction: '',
|
||||
MainContainer: mainContainer,
|
||||
SelectedContainerId: mainContainer.properties.id,
|
||||
TypeCounters: {},
|
||||
Symbols: new Map(),
|
||||
SelectedSymbolId: ''
|
||||
}
|
||||
],
|
||||
historyCurrentStep: 0
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Default config when the API is not available
|
||||
*/
|
||||
export const DEFAULT_CONFIG: IConfiguration = {
|
||||
AvailableContainers: [
|
||||
{
|
||||
|
@ -53,9 +88,12 @@ export const DEFAULT_CONFIG: IConfiguration = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Default Main container properties
|
||||
*/
|
||||
export const DEFAULT_MAINCONTAINER_PROPS: IContainerProperties = {
|
||||
id: 'main',
|
||||
parentId: 'null',
|
||||
parentId: '',
|
||||
linkedSymbolId: '',
|
||||
displayedText: 'main',
|
||||
x: 0,
|
||||
|
@ -72,6 +110,16 @@ export const DEFAULT_MAINCONTAINER_PROPS: IContainerProperties = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the default properties of a newly created container
|
||||
* @param type Type of the container
|
||||
* @param typeCount index of the container
|
||||
* @param parent Parent of the container
|
||||
* @param x horizontal offset
|
||||
* @param y vertical offset
|
||||
* @param containerConfig default config of the container sent by the API
|
||||
* @returns {IContainerProperties} Default properties of a newly created container
|
||||
*/
|
||||
export const GetDefaultContainerProps = (
|
||||
type: string,
|
||||
typeCount: number,
|
||||
|
@ -96,3 +144,20 @@ export const GetDefaultContainerProps = (
|
|||
style: structuredClone(containerConfig.Style),
|
||||
userData: structuredClone(containerConfig.UserData)
|
||||
});
|
||||
|
||||
export const GetDefaultSymbolModel = (
|
||||
name: string,
|
||||
newCounters: Record<string, number>,
|
||||
type: string,
|
||||
symbolConfig: IAvailableSymbol
|
||||
): ISymbolModel => {
|
||||
return {
|
||||
id: `${name}-${newCounters[type]}`,
|
||||
type: name,
|
||||
config: structuredClone(symbolConfig),
|
||||
x: 0,
|
||||
width: symbolConfig.Width ?? DEFAULT_SYMBOL_WIDTH,
|
||||
height: symbolConfig.Height ?? DEFAULT_SYMBOL_HEIGHT,
|
||||
linkedContainers: new Set()
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue