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

kalpa-tree-on-page

v1.0.4

Published

A little code which makes kalpa-tree more friendly as a load-on-demand piece of code

Downloads

27

Readme

Kalpa Tree on Page

For creating editable trees on the web, the package Kalpa Tree is absolutely fantastic. It's fast, flexible, pretty, and will handle 10s or 100s of thousands of nodes. It's well worth using.

However...

It was designed to work as part of a single-page application. If, instead, you want to use it occassionally and conditionally on a web page, it benefits from a little glue code (which is what this package is).

This package has compiled js and css from the kalpa tree package which can be loaded directly by the browser. Not only does it make it simpler to use Kalpa Tree as a "plugin", it simplifies the install and compile tool chain.

Install

npm install kalpa-tree-on-page

First Steps

const makeTree = require('kalpa-tree-on-page')

makeTree({
	data: data
}).then(tree => {

	// Do something with the tree
})
<div id="kalpa-tree" style="width: 500px; height: 500px;">
	
</div>

For this package to work, you must:

  • Have the resources from the kalpa-tree-on-page/public directory available for url based access
  • Have a container element created

If you are using Webhandle, makeing sure the resources are on the path can be done like:

const kalpaTreeOnPage = require('kalpa-tree-on-page')
const webhandle = require('webhandle')
kalpaTreeOnPage(webhandle)

Options

There are a number of options for quick setup.

{
	treeContainerSelector: '#kalpa-tree' // Where the tree will go
	, stream: nodeStream // stream of nodes for the tree. This can be as simple as an EventEmitter where you emit 'data' events.
	, loadStyles: true 	// whether to load a stylesheet
	, styleLocation: '/kalpa-tree-on-page/css/white-page-tree.css' // the stylesheet url to load
	, scriptLocation: '/kalpa-tree-on-page/js/kalpa-tree.js' // the compiled kalpa tree url to load
	, data: dataArray // an array of nodes. probably either use this or the stream parameter
}

Each node, whether in the data array or coming from the stream need to look like:

{
	"id": 1002, // must have a unique numeric id
	"label": "node 2", // should have a label
	"parentId": 1001 // determines under which node it will be placed, the root node will not have a parent id
	// Also you can add other attributes
}

Usage

Check out the Kalpa Tree documentation for how to use the tree as part of an app/page.