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

simple-treeview

v0.0.9

Published

Awfully basic JavaScript treeview component.

Downloads

444

Readme

simple-treeview

Awfully basic JavaScript treeview component.

  • API documentation: https://unpkg.com/simple-treeview/docs/index.html
  • Live demo
    • Vanilla: https://unpkg.com/simple-treeview/examples/vanilla.html
    • Bootstrap: https://unpkg.com/simple-treeview/examples/bootstrap.html

Usage

Vanilla Tree View

  • Include the treeview CSS:
<link rel="stylesheet" href="https://unpkg.com/simple-treeview/dist/treeview.vanilla.css">
  • If you want to use Font Awesome icons, include its CSS as well:
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
  • Load the treeview JavaScript (as an ES module), and use the VanillaTreeView class:
<script type="module">
    import { VanillaTreeView } from 'https://unpkg.com/simple-treeview/dist/treeview.vanilla.js';
    let tree = new VanillaTreeView(document.getElementById('tree'), {
        provider: {
            async getChildren(id) {
                if (!id) {
                    return [
                        { id: 'p1', label: 'Parent #1', icon: { classes: ['far', 'fa-folder'] }, state: 'collapsed' },
                        { id: 'p2', label: 'Parent #2', icon: { classes: ['far', 'fa-folder'] }, state: 'expanded' }
                    ];
                } else {
                    await new Promise((resolve, reject) => setTimeout(resolve, 1000)); // Simulate 1s delay
                    switch (id) {
                        case 'p1':
                            return [
                                { id: 'c1', label: 'Child #1', icon: { classes: ['far', 'fa-file'] }, state: 'collapsed' },
                                { id: 'c2', label: 'Child #2', icon: { classes: ['far', 'fa-file'] } }
                            ];
                        case 'p2':
                            return [
                                { id: 'c3', label: 'Child #3', icon: { classes: ['far', 'fa-file'] } },
                                { id: 'c4', label: 'Child #4', icon: { classes: ['far', 'fa-file'] } }
                            ];
                        case 'c1':
                            return [
                                { id: 'g1', label: 'Grandchild #1', icon: { classes: ['far', 'fa-clock'] } }
                            ];
                        default:
                            return [];
                    }
                }
            }
        }
    });
</script>

Bootstrap Tree View

  • Make sure you include Bootstrap dependencies (incl. Bootstrap Icons if you want to use those, too), for example:
<!-- CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  • Include the treeview CSS:
<link rel="stylesheet" href="https://unpkg.com/simple-treeview/dist/treeview.bootstrap.css">
  • Load the treeview JavaScript (as an ES module), and use the BootstrapTreeView class:
<script type="module">
    import { BootstrapTreeView } from 'https://unpkg.com/simple-treeview/dist/treeview.bootstrap.js';
    let tree = new BootstrapTreeView(document.getElementById('tree'), {
        provider: {
            async getChildren(id) {
                if (!id) {
                    return [
                        { id: 'p1', label: 'Parent #1', icon: { classes: ['bi', 'bi-folder'] }, state: 'collapsed' },
                        { id: 'p2', label: 'Parent #2', icon: { classes: ['bi', 'bi-folder'] }, state: 'expanded' }
                    ];
                } else {
                    await new Promise((resolve, reject) => setTimeout(resolve, 1000));
                    switch (id) {
                        case 'p1':
                            return [
                                { id: 'c1', label: 'Child #1', icon: { classes: ['bi', 'bi-file-earmark'] }, state: 'collapsed' },
                                { id: 'c2', label: 'Child #2', icon: { classes: ['bi', 'bi-file-earmark'] } }
                            ];
                        case 'p2':
                            return [
                                { id: 'c3', label: 'Child #3', icon: { classes: ['bi', 'bi-file-earmark'] } },
                                { id: 'c4', label: 'Child #4', icon: { classes: ['bi', 'bi-file-earmark'] } }
                            ];
                        case 'c1':
                            return [
                                { id: 'g1', label: 'Grandchild #1', icon: { classes: ['bi', 'bi-clock'] } }
                            ];
                        default:
                            return [];
                    }
                }
            }
        }
    });
</script>