# kalpa-tree-on-page

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

Latest version **1.0.9** (published 2026-05-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install kalpa-tree-on-page
pnpm add kalpa-tree-on-page
yarn add kalpa-tree-on-page
bun add kalpa-tree-on-page
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2026-05-07 |
| First published | 2023-10-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 880.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | dankolz |

## Links

- npm: https://www.npmjs.com/package/kalpa-tree-on-page
- Repository: https://github.com/EmergentIdeas/kalpa-tree-on-page
- Homepage: https://github.com/EmergentIdeas/kalpa-tree-on-page#readme
- Issues: https://github.com/EmergentIdeas/kalpa-tree-on-page/issues
- npm.io page: https://npm.io/package/kalpa-tree-on-page

## Dependencies (3)

- [@webhandle/backbone-view](https://npm.io/package/@webhandle/backbone-view.md) ^1.0.4
- [@webhandle/minimal-browser-event-emitter](https://npm.io/package/@webhandle/minimal-browser-event-emitter.md) ^1.0.4
- [@webhandle/initialize-webhandle-component](https://npm.io/package/@webhandle/initialize-webhandle-component.md) ^1.0.2

## Recent versions

- 1.0.9 (latest) — 2026-05-07
- 1.0.8 — 2026-03-20
- 1.0.7 — 2026-03-20
- 1.0.6 — 2026-03-20
- 1.0.5 — 2026-02-23
- 1.0.4 — 2024-07-17
- 1.0.3 — 2024-02-12
- 1.0.2 — 2023-11-10
- 1.0.1 — 2023-11-10
- 1.0.0 — 2023-10-18

## README

# Kalpa Tree on Page

For creating editable trees on the web, the package [Kalpa Tree](https://www.npmjs.com/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

```bash
npm install kalpa-tree-on-page
```





## Usage as a Webhandle Component

### Server side

```js
import kalpaTreeSetup from "kalpa-tree-on-page/initialize-webhandle-component.mjs"
let kalpaTreeManager = await kalpaTreeSetup(webhandle)
```

A component that uses it should call
```js
kalpaTreeManager.addExternalResources(externalResourcesManager)
```

Alternatively, the dependencies can be included via a template

```html
__::kalpa-tree-on-page/renderExternalResources__
```

Then you can do this:

```html

<div id="tree" style="position: relative; border: solid 1px black; width: 500px; height: 800px;">

</div>


<script type="module">
	import KalpaTreeView from "kalpa-tree-on-page/kalpa-tree-view"

	let data = [
		{
			"id": 0, 
			"label": "node 1", 
		}
		, {
			"id": 1002, 
			"label": "node 2", 
			"parentId": 0 
		}
		, {
			"id": 1003, 
			"label": "node 3", 
			"parentId": 0 
		}
		, {
			"id": 1004, 
			"label": "node 4", 
			"parentId": 1003 
		}
	]

	let holder = document.getElementById('tree')
	let tree = new KalpaTreeView({
		data: data
	})
	await tree.render()
	tree.appendTo(holder)
	
	tree.tree.editable()
	
	window.tree = tree
	
	tree.emitter.on('move', (data) => {
		console.log('move')
		console.log(data)
	})
	tree.emitter.on('select', (data) => {
		console.log('select')
		console.log(data)
	})

</script>


```








## The Older Style of Use

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

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

	// Do something with the tree
})

```

```html
<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](https://www.npmjs.com/package/webhandle), makeing sure the resources
are on the path can be done like:

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


## Options

There are a number of options for quick setup.

```js
{
	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:

```js
{
	"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.

---
_Source: https://npm.io/package/kalpa-tree-on-page · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
