@tacman1123/jstree-esm
v4.0.0
Published
jsTree v4 fork with Stimulus-first API and native DOM events
Readme
jsTree v4 (Fork)
This repository is a v4 fork of vakata/jstree focused on:
- modern no-build demos,
- Stimulus-first usage,
- native DOM events for non-jQuery consumers,
- keeping jQuery as an internal runtime dependency.
The classic jQuery plugin API is still available as a compatibility path.
Install
npm install @tacman1123/jstree-esmPackage entry points
@tacman1123/jstree-esm- ESM function API@tacman1123/jstree-esm/module- direct module API@tacman1123/jstree-esm/browser-module- browser-global API helpers@tacman1123/jstree-esm/stimulus- Stimulus controller scaffold@tacman1123/jstree-esm/jquery-plugin- legacy plugin compatibility path
ESM function API
import { createTree, getTree, callTree, destroyTree } from '@tacman1123/jstree-esm';
const el = document.getElementById('my-tree');
createTree(el, {
core: {
data: [{ text: 'Root', children: [{ text: 'Child' }] }]
}
});
callTree(el, 'open_all');
const instance = getTree(el);
destroyTree(el);Stimulus controller usage
import { Application } from '@hotwired/stimulus';
import JsTreeController from '@tacman1123/jstree-esm/stimulus';
const app = Application.start();
app.register('jstree', JsTreeController);The bundled controller is a scaffold and intended for extension in app code.
Events
jsTree triggers jQuery events and also dispatches native CustomEvents.
For an event like changed:
- jQuery event:
changed.jstree - native event (preferred):
changed.jstree - native compatibility alias:
jstree:changed
const el = document.getElementById('tree');
el.addEventListener('changed.jstree', (event) => {
console.log(event.detail);
});Disable native dispatch with core.dispatch_events: false.
Local development
Start a local server from repository root:
php -S 127.0.0.1:8000 -t .Then open:
http://127.0.0.1:8000/launcherhttp://127.0.0.1:8000/demo/modern/index.htmlmodern Stimulus demohttp://127.0.0.1:8000/demo/module/index.htmlfunction API demohttp://127.0.0.1:8000/demo/basic/index.htmllegacy jQuery API coverage demo
License
MIT. Keep LICENSE-MIT and upstream copyright notices.
