message: refactor(changes): handle expand parent on dimension update
diff: import { Node, Edge, EdgeChange, NodeChange } from '../types';
  -function applyChanges(changes: NodeChange[] | EdgeChange[], elements: any[]): any[] {
  - const initElements: any[] = [];
  -
  - return elements.reduce((res: any[], item: any) => {
  - const currentChange = changes.find((c) => c.id === item.id);
  -
  - if (currentChange) {
  - switch (currentChange.type) {
  - case 'select': {
  - res.push({ ...item, selected: currentChange.selected });
  - return res;
  - }
  - case 'position': {
  - const updateItem = { ...item };
  -
  - if (typeof currentChange.position !== 'undefined') {
  - updateItem.position = currentChange.position;
  - }
  -
  - if (typeof currentChange.dragging !== 'undefined') {
  - updateItem.dragging = currentChange.dragging;
  - }
  -
  - if (updateItem.expandParent) {
  +function handleParentExpand(res: any[], updateItem: any) {
  const parent = res.find((e) => e.id === updateItem.parentNode);
  if (parent) {
  @@ -34,10 +11,16 @@ function applyChanges(changes: NodeChange[] | EdgeChange[], elements: any[]): an
  parent.style = { ...parent.style } || {};
  if (extendWidth > 0) {
  + if (!parent.style.width) {
  + parent.style.width = parent.width;
  + }
  parent.style.width += extendWidth;
  }
  if (extendHeight > 0) {
  + if (!parent.style.height) {
  + parent.style.height = parent.height;
  + }
  parent.style.height += extendHeight;
  }
  @@ -61,6 +44,33 @@ function applyChanges(changes: NodeChange[] | EdgeChange[], elements: any[]): an
  }
  }
  +function applyChanges(changes: NodeChange[] | EdgeChange[], elements: any[]): any[] {
  + const initElements: any[] = [];
  +
  + return elements.reduce((res: any[], item: any) => {
  + const currentChange = changes.find((c) => c.id === item.id);
  +
  + if (currentChange) {
  + switch (currentChange.type) {
  + case 'select': {
  + res.push({ ...item, selected: currentChange.selected });
  + return res;
  + }
  + case 'position': {
  + const updateItem = { ...item };
  +
  + if (typeof currentChange.position !== 'undefined') {
  + updateItem.position = currentChange.position;
  + }
  +
  + if (typeof currentChange.dragging !== 'undefined') {
  + updateItem.dragging = currentChange.dragging;
  + }
  +
  + if (updateItem.expandParent) {
  + handleParentExpand(res, updateItem);
  + }
  +
  res.push(updateItem);
  return res;
  }
  @@ -72,6 +82,10 @@ function applyChanges(changes: NodeChange[] | EdgeChange[], elements: any[]): an
  updateItem.height = currentChange.dimensions.height;
  }
  + if (updateItem.expandParent) {
  + handleParentExpand(res, updateItem);
  + }
  +
  res.push(updateItem);
  return res;
  }
  