diff --git a/src/Components/Editor/Actions/AddContainer.ts b/src/Components/Editor/Actions/AddContainer.ts index 056a7c5..2cca395 100644 --- a/src/Components/Editor/Actions/AddContainer.ts +++ b/src/Components/Editor/Actions/AddContainer.ts @@ -193,8 +193,7 @@ function AddNewContainerToParent( newContainer, configuration, containerConfig, - newCounters, - symbols + newCounters ); } else { InitializeChildrenWithPattern( @@ -257,8 +256,7 @@ function InitializeDefaultChild( newContainer: ContainerModel, configuration: IConfiguration, containerConfig: IAvailableContainer, - newCounters: Record, - symbols: Map + newCounters: Record ): void { if (containerConfig.DefaultChildType === undefined) { return; @@ -279,15 +277,45 @@ function InitializeDefaultChild( seen.add(currentConfig.Type); - const newChildContainer = AddNewContainerToParent( - currentConfig, - configuration, + /// TODO: REFACTOR this with AddContainerToParent /// + const left: number = currentConfig.Margin?.left ?? 0; + const bottom: number = currentConfig.Margin?.bottom ?? 0; + const top: number = currentConfig.Margin?.top ?? 0; + const right: number = currentConfig.Margin?.right ?? 0; + let x = currentConfig.X ?? 0; + let y = currentConfig.Y ?? 0; + let width = currentConfig.Width ?? currentConfig.MaxWidth ?? currentConfig.MinWidth ?? parent.properties.width; + let height = currentConfig.Height ?? parent.properties.height; + + ({ x, y, width, height } = ApplyMargin(x, y, width, height, left, bottom, top, right)); + + UpdateCounters(newCounters, currentConfig.Type); + const count = newCounters[currentConfig.Type]; + const defaultChildProperties = GetDefaultContainerProps( + currentConfig.Type, + count, parent, - 0, 0, - newCounters, - symbols + x, + y, + width, + height, + currentConfig ); + // Create the container + const newChildContainer = new ContainerModel( + parent, + defaultChildProperties, + [], + { + type: currentConfig.Type + } + ); + + // And push it the the parent children + parent.children.push(newChildContainer); + /// /// + // iterate depth++; parent = newChildContainer;