npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

layoutcontainer

v1.1.3

Published

Layout Container ---- Layout Container is the resizing engine that can automatically calculates the correct position of cooresponding regions of the container when user change the position of the splitter in the container. User could achieve the drag-r

Downloads

4

Readme

Layout Container

Layout Container is the resizing engine that can automatically calculates the correct position of cooresponding regions of the container when user change the position of the splitter in the container. User could achieve the drag-resize behavior by providing the drag offsets to this engine and it will update the data accordingly. Also, event will be emitted to notify consumer the change in the data model. See demo:

Live Demo: https://xiaoyual666.github.io/layoutcontainer/

Installation

> npm i layoutcontainer

Concepts

1. Container, Region and Cell

A layout container contains at most 5 regions: regions

Each region could be either a cell or a layout container, thus we have the flexibility to build complete layout structure.

2. Splitter

Splitters are the edges that seperate different regions within a container. We will handle the resizing of corresponding regions when you move the splitters: splitters

3. Path

Path is an array of strings that represent the regions. For example, the path for trailing splitter or trailing cell in side a center region of a root container is:

let path = ["center","trailing"]

Easy as 1-2-3

1. Prepare data

use data to represent layout structure.

data structure for container

{
  id: "unique id for this container"
  path: ["center"] // ex. this is the center region of its parent container
  top: dataForTopCell // this can either be a container or a cell
  leading: dataForLeadingCell // this can either be a container or a cell
  center: dataForCenterCell // this can either be a container or a cell
  trailing: dataForTrailingCell // this can either be a container or a cell
  bottom: dataForBottomCell // this can either be a container or a cell
}

data structure for cell

{
  id: "unique id for this cell"
  path: ["center"] // ex. this is the center region of its parent container
  x: 10,
  y: 50,
  width: 100,
  height: 100,
  availableHorizontalSpace: 90,  // ex. when resizing, the width will be reduced no more than 90px
  availableVerticalSpace: 80 // ex. when resizing, the height will be reduced no more than 80
}

data example:

let rootStructureData = {
      id: "container 1"
      path: [] 
      top: {
          id: "cell_1",
          path: ["top"],
          x: 100,
          y: 200,
          width: 300,
          height: 400,
          availbleHorizontalSpace: 50,
          availableVerticalSpace: 50
      }
      center:{
          id: "cell_2",
          path: ["center"],
          x: 100,
          y: 600,
          width: 300,
          height: 400,
          availbleHorizontalSpace: 50,
          availableVerticalSpace: 50
      }
    }

2. Create LayoutContainer instance

const LayoutContainer = require("Layoutcontainer")
let rootContainer = LayoutContainer(rootStructureData)

3. Resize

rootContainer.resizeBySplitter(["top"], [100,200])

API

1. constructor

we pass data representing the structure of layout into constructor to get the instance

let layoutContainer = new LayoutContainer(dataForRootContainer)

for data representing container, the details of object is:

| properties | type | description | | ------------- |-------------| -----| | id | String | unique string that used to identify the container | | path | Array | array of strings to locate the region or splitter | | top | container or cell | top region of the container | | leading | container or cell | leading region of the container | | center | container or cell | center region of the container | | trailing | container or cell | trailing region of the container | | bottom | container or cell | bottom region of the container |

for data representing cell, the details of object is:

| properties | type | description | | ------------- |-------------| -----| | id | String | unique string that used to identify the container | | path | Array | array of strings to locate the region or splitter | | x | Number | x position of cell | | y | Number | y position of cell | | width |Number | width of cell | | height | Number | height of cell | | availableHorizontalSpace | Number | how much pixel could this cell be reduced horizontally when resizing | | availableVerticalSpace | Number | how much pixel could this cell be reduced vertically when resizing |

2. resizeBySplitter( path, offsets )

resize corresponding regions by dragging a specific splitter defined by path.

| Parameter|type| Description| |----|----|----| | path | Array | array of string that represents the splitter. Ex. ["center", "top"]| | offsets | [Number, Number] | dragging offset. offsets[0] is the x offset, offsets[1] is the y offset.

Example:

layoutContainer.resizeBySplitter(["leading"], [10,30]) // drag the leading splitter 

2. resizeByEdge( edge, offset )

resize entire layout container by dragging edge of it.

| Parameter|type| Description| |----|----|----| | edge | "top" or "bottom" or "left" or "right" | string that represents the edge | | offset | Number | dragging offset. Ex. if you move the left edge, offset will be the x offset.

Example:

layoutContainer.resizeByEdge("left",  50) // drag the left edge from left to right by 50px.

3. Event

if you are using library like React or Vue, you may not need this. Because the data will be reactive. However, we still provide event for you to listen to the change of the model, and you could update the view accordingly.

| Event Name | Fired When | | ---- |---- | | resizing | when x or y or width or height changed on a cell |

| Event Data | Description | | ---- |---- | | state | the data representing the current resized cell | | key | indicates which property is changed, it is useful when you want to optimize the updating logic for you view |

Example: (more detail could be fould in the example folder)

const LayoutContainer = require("layoutcontainer")

let rootData = getRootData(), // provide root data, you need to implement this function
    layoutContainer = new LayoutContainer(rootData),
    view = generateViewForLayout(rootData) // you could initialize the view according to the data structure

LayoutContainer.on("resizing", ({state, key}) => {
    updateViewForCellByState(state) // you could implement logic to update the view manually if you dont use MVVM library.
})