Merged PR 216: Deprecate parent from IContainerModel for FindContainerById
This commit is contained in:
parent
d40cd8cf8e
commit
b4eba6bb9b
19 changed files with 97 additions and 109 deletions
|
@ -18,12 +18,11 @@ export function ApplyBehaviors(containers: Map<string, IContainerModel>, contain
|
|||
try {
|
||||
const symbol = symbols.get(container.properties.linkedSymbolId);
|
||||
if (container.properties.linkedSymbolId !== '' && symbol !== undefined) {
|
||||
ApplySymbol(container, symbol);
|
||||
ApplySymbol(containers, container, symbol);
|
||||
}
|
||||
|
||||
if (container.parent !== undefined && container.parent !== null) {
|
||||
const parent = container.parent;
|
||||
|
||||
const parent = FindContainerById(containers, container.properties.parentId);
|
||||
if (parent !== undefined && parent !== null) {
|
||||
if (container.properties.isAnchor) {
|
||||
ApplyAnchor(containers, container, parent);
|
||||
}
|
||||
|
@ -69,11 +68,12 @@ export function ApplyBehaviorsOnSiblingsChildren(
|
|||
containers: Map<string, IContainerModel>,
|
||||
newContainer: IContainerModel,
|
||||
symbols: Map<string, ISymbolModel>): void {
|
||||
if (newContainer.parent === null || newContainer.parent === undefined) {
|
||||
const parent = FindContainerById(containers, newContainer.properties.parentId);
|
||||
if (parent === null || parent === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
newContainer.parent.children
|
||||
parent.children
|
||||
.forEach((containerId: string) => {
|
||||
const container = FindContainerById(containers, containerId);
|
||||
|
||||
|
@ -81,8 +81,9 @@ export function ApplyBehaviorsOnSiblingsChildren(
|
|||
return;
|
||||
}
|
||||
|
||||
if (container.parent !== null) {
|
||||
UpdateWarning(containers, container, container.parent);
|
||||
const containerParent = FindContainerById(containers, container.properties.parentId);
|
||||
if (containerParent !== null && containerParent !== undefined) {
|
||||
UpdateWarning(containers, container, containerParent);
|
||||
}
|
||||
|
||||
if (container === newContainer) {
|
||||
|
@ -102,11 +103,12 @@ export function ApplyBehaviorsOnSiblingsChildren(
|
|||
* @returns
|
||||
*/
|
||||
export function ApplyBehaviorsOnSiblings(containers: Map<string, IContainerModel>, newContainer: IContainerModel, symbols: Map<string, ISymbolModel>): void {
|
||||
if (newContainer.parent === null || newContainer.parent === undefined) {
|
||||
const parent = FindContainerById(containers, newContainer.properties.parentId);
|
||||
if (parent === null || parent === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
newContainer.parent.children
|
||||
parent.children
|
||||
.forEach((containerId: string) => {
|
||||
const container = FindContainerById(containers, containerId);
|
||||
|
||||
|
@ -116,8 +118,9 @@ export function ApplyBehaviorsOnSiblings(containers: Map<string, IContainerModel
|
|||
|
||||
ApplyBehaviors(containers, container, symbols);
|
||||
|
||||
if (container.parent != null) {
|
||||
UpdateWarning(containers, container, container.parent);
|
||||
const containerParent = FindContainerById(containers, container.properties.parentId);
|
||||
if (containerParent !== null && containerParent !== undefined) {
|
||||
UpdateWarning(containers, container, containerParent);
|
||||
}
|
||||
|
||||
if (container === newContainer) {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { IContainerModel } from '../../../Interfaces/IContainerModel';
|
|||
import { ISizePointer } from '../../../Interfaces/ISizePointer';
|
||||
import { Orientation } from '../../../Enums/Orientation';
|
||||
import { ENABLE_HARD_RIGID } from '../../../utils/default';
|
||||
import { MakeChildrenIterator } from '../../../utils/itertools';
|
||||
import { FindContainerById, MakeChildrenIterator } from '../../../utils/itertools';
|
||||
|
||||
/**
|
||||
* "Transform the container into a rigid body"
|
||||
|
@ -122,17 +122,18 @@ export function ConstraintBodyInsideUnallocatedWidth(
|
|||
containers: Map<string, IContainerModel>,
|
||||
container: IContainerModel
|
||||
): IContainerModel {
|
||||
if (container.parent === null || container.parent === undefined) {
|
||||
const parent = FindContainerById(containers, container.properties.parentId);
|
||||
if (parent === null || parent === undefined) {
|
||||
return container;
|
||||
}
|
||||
|
||||
// Get the available spaces of the parent
|
||||
const isHorizontal =
|
||||
container.parent.properties.orientation === Orientation.Horizontal;
|
||||
const children: IContainerModel[] = [...MakeChildrenIterator(containers, container.parent.children)];
|
||||
parent.properties.orientation === Orientation.Horizontal;
|
||||
const children: IContainerModel[] = [...MakeChildrenIterator(containers, parent.children)];
|
||||
const availableWidths = GetAvailableWidths(
|
||||
0,
|
||||
container.parent.properties.width,
|
||||
parent.properties.width,
|
||||
children,
|
||||
container,
|
||||
isHorizontal
|
||||
|
@ -172,7 +173,7 @@ export function ConstraintBodyInsideUnallocatedWidth(
|
|||
container,
|
||||
0,
|
||||
availableWidthFound.x,
|
||||
container.parent.properties.width,
|
||||
parent.properties.width,
|
||||
availableWidthFound.width
|
||||
);
|
||||
|
||||
|
@ -203,7 +204,7 @@ export function ConstraintBodyInsideUnallocatedWidth(
|
|||
availableWidthFound.x,
|
||||
0,
|
||||
availableWidthFound.width,
|
||||
container.parent.properties.height
|
||||
parent.properties.height
|
||||
);
|
||||
|
||||
return container;
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import { IContainerModel } from '../../../Interfaces/IContainerModel';
|
||||
import { ISymbolModel } from '../../../Interfaces/ISymbolModel';
|
||||
import { ApplyParentTransform } from '../../../utils/itertools';
|
||||
import { ApplyParentTransform, FindContainerById } from '../../../utils/itertools';
|
||||
import { RestoreX, TransformX } from '../../../utils/svg';
|
||||
|
||||
export function ApplySymbol(container: IContainerModel, symbol: ISymbolModel): IContainerModel {
|
||||
export function ApplySymbol(containers: Map<string, IContainerModel>, container: IContainerModel, symbol: ISymbolModel): IContainerModel {
|
||||
container.properties.x = TransformX(symbol.x, symbol.width, symbol.config.PositionReference);
|
||||
container.properties.x = RestoreX(container.properties.x, container.properties.width, container.properties.positionReference);
|
||||
const [x] = ApplyParentTransform(container.parent, container.properties.x, 0);
|
||||
const parent = FindContainerById(containers, container.properties.parentId);
|
||||
let x = 0;
|
||||
if (parent !== undefined && parent !== null) {
|
||||
([x] = ApplyParentTransform(containers, parent, container.properties.x, 0));
|
||||
}
|
||||
container.properties.x = x;
|
||||
return container;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue