How to use the react-mosaic-component.createBalancedTreeFromLeaves function in react-mosaic-component

To help you get started, we’ve selected a few react-mosaic-component examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ProjectMirador / mirador / src / components / WorkspaceMosaic.js View on Github external
// Windows were added
    if (!sortedWindows.every(e => leaveKeys.includes(e))) {
      // No current layout, so just generate a new one
      if (leaveKeys.length < 2) {
        return createBalancedTreeFromLeaves(sortedWindows);
      }
      // Add new windows to layout
      const addedWindows = difference(sortedWindows, leaveKeys);
      const newLayout = new MosaicLayout(layout);
      newLayout.addWindows(addedWindows);
      return newLayout.layout;
    }
    // Windows were removed (perhaps in a different Workspace). We don't have a
    // way to reconfigure.. so we have to random generate
    if (!leaveKeys.every(e => sortedWindows.includes(e))) {
      return createBalancedTreeFromLeaves(sortedWindows);
    }
    return layout;
  }
github ProjectMirador / mirador / src / components / WorkspaceMosaic.js View on Github external
determineWorkspaceLayout() {
    const { windows, layout } = this.props;
    const sortedWindows = toPairs(windows)
      .sort((a, b) => a.layoutOrder - b.layoutOrder).map(val => val[0]);
    const leaveKeys = getLeaves(layout);
    // Windows were added
    if (!sortedWindows.every(e => leaveKeys.includes(e))) {
      // No current layout, so just generate a new one
      if (leaveKeys.length < 2) {
        return createBalancedTreeFromLeaves(sortedWindows);
      }
      // Add new windows to layout
      const addedWindows = difference(sortedWindows, leaveKeys);
      const newLayout = new MosaicLayout(layout);
      newLayout.addWindows(addedWindows);
      return newLayout.layout;
    }
    // Windows were removed (perhaps in a different Workspace). We don't have a
    // way to reconfigure.. so we have to random generate
    if (!leaveKeys.every(e => sortedWindows.includes(e))) {
      return createBalancedTreeFromLeaves(sortedWindows);
    }
    return layout;
  }