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

@laplacek/ng2-simple-tree

v1.0.2

Published

Simple template-driven tree for Angular2 using directives instead of components

Downloads

5

Readme

ng2-simple-tree

Simple markup-driven tree for Angular2

Why?

Because of need for very simple markup-driven tree basing on directives applicable to any HTML element.

Setup

Package installation

npm install @laplacek/ng2-simple-tree –-save

Importing module

@NgModule({
  imports: [SimpleTreeModule /*, … */]
})
export class SharedModule { }

Building tree

Defining tree

Tree can be aplied on any markup element. Just use simple-tree directive for a tree root and simple-tree-node defining tree nodes. Every simple-tree-node inside other simple-tree-node becomes it’s child.

<ul simple-tree>
  <li simple-tree-node [(isCurrentNode)]="doYouLikeFruits">
    <span>Fruits</span>
    <ul>
      <li simple-tree-node>Banana</li>
      <li simple-tree-node>
        <span>Apple</span>
        <ul>
          <li simple-tree-node>Yellow</li>
          <li simple-tree-node>Red</li>
        </ul>
      </li>
      <li simple-tree-node>Orange</li>
    </ul>
  </li>
  <li simple-tree-node [isCurrentNode]="true">
    <span>Vegetables</span>
    <ul>
      <li simple-tree-node>Tomato</li>
      <li simple-tree-node>Carrot</li>
    </ul>
  </li>
  <li simple-tree-node>No children item</li>
</ul>

Defining one tree inside another

One simple tree can contain the other. The trees are then independent, so selecting/deselecting node in one, will not affect the nodes in another.

<ul simple-tree>
  <li simple-tree-node>
    <span>Cars</span>
    <ul>
      <li simple-tree-node>Trucks</li>
      <li simple-tree-node>
        <span>Roadsters</span>
        <ul simple-tree> <!--Another, independent tree is defined-->
          <li simple-tree-node>BMW Z4</li>
          <li simple-tree-node>Mazda MX5</li>
        </ul>
      </li>
      <li simple-tree-node>Orange</li>
    </ul>
  </li>
  <li simple-tree-node>Boats</li>
</ul>

Using tree

Current node element has current-node class set.
Tree node element beeing current or having any current descendant has active-node class set.

Accessing tree

From component inside the tree

Every simple-tree directive provides a SimpleTreeNavigator service. That means, that navigator for current tree is accessible via Angular2 Dependency Injection mechanism in every child component of our tree.

@Component({
  // ...
})
export class TreeAwareComponent {
    currentPath: Observable<string> = this._simpleTreeNavigator.treePath;  //observable with current path
    
    constructor(private _simpleTreeNavigator: SimpleTreeNavigator){ }
    
    goBack() {
        this._simpleTreeNavigator.goUp(); //go up in three
    }
}

From every other place in code

Every tree can also be accessed from any other place in code.
To do that the tree must be defined with a name:

<div simple-tree="CarsTree">
  <div>Cars</div>
  <div simple-tree-node>BMW</div>
  <div simple-tree-node>Mazda</div>
  <div simple-tree-node>
      <span>Toyota</span>
        <div simple-tree-node>Corolla</div>
        <div simple-tree-node>RAV 4</div>
  </div>    
</div>

It's SimpleTreeNavigator can than be accessed via SimpleTreeNavigatorsProvider:

@Injectable()
export class TreeAwareService {
    constructor(private _simpleTreeNavigatorsProvider: SimpleTreeNavigatorsProvider){ }
    
    goUp() {
        let navigator = this._simpleTreeNavigatorsProvider.get('CarsTree');
        navigator.goUp();
    }
}