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

aurelia-jstree

v1.1.0

Published

Aurelia wrapper component for jsTree

Downloads

28

Readme

aurelia-jstree

An Aurelia wrapper component for jsTree.

Install

Make sure to npm install jQuery and jsTree alongside this wrapper.

npm install jquery jstree aurelia-jstree --save

Aurelia CLI Support

If your Aurelia CLI build is based on RequireJS or SystemJS you can setup the plugin using the following dependency declaration:

...
"dependencies": [
  {
    "name":"jquery",
    "path":"../node_modules/jquery/dist",
    "main":"jquery.min",
    "export": "$"
  },
  {
    "name":"jstree",
    "path":"../node_modules/jstree/dist",
    "main":"jstree.min"
  },
  {
    "name": "aurelia-jstree",
    "path": "../node_modules/aurelia-jstree/dist/amd",
    "main": "index"
  }
]

Configuration

In your main.ts you'll have to load jstree and register the plugin:

import {Aurelia} from 'aurelia-framework'
import environment from './environment';
import "jstree"; // <------------ MAKE SURE TO IMPORT JSTREE
import 'jstree/themes/default/style.min.css';  // <----- IMPORT STYLES OR INCLUDE BY ANY OTHER MEANS (SCSS, direct include ...)

export function configure(aurelia: Aurelia) {
  aurelia.use
    .standardConfiguration()
    .feature('resources');

  ...

  aurelia.use.plugin("aurelia-jstree");  // <----- REGISTER THE PLUGIN

  aurelia.start().then(() => aurelia.setRoot());
}

Usage

Once the plugin is installed and configured you can use the au-js-tree custom component. An example for a simple filebrowser is provided below:

<au-js-tree settings.bind="jstreeConfig"
            data.bind="data"
            selection-changed.bind="onSelectionChanged"
            node-moved.bind="onNodeMoved"></au-js-tree>

The settings.core should not contain the data property. It should be provided separately via the data binding to ensure proper re-renders on prop changes.

export class App {
  public jstreeConfig = {
    plugins: ["dnd"],
    core: {
      check_callback: function (operation, node, node_parent, node_position, more) {
        // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node' or 'copy_node'
        console.log(operation);
        if (operation === "move_node") {
          console.group("D&D");
          console.log("node", node);
          console.log("parent", node_parent);
          console.log("position", node_position);
          console.log("more", more);
          console.log(node_parent.original.isFolder);
          console.groupEnd();
          
          return node_parent.original.isFolder === true; //only allow dropping inside folders
        }
        return true;  //allow all other operations
      }
    },
    dnd: {
      check_while_dragging: true
    }
  }

  public data = [
    {
      text: "Root folder",
      state: { opened: true },
      isFolder: true,
      children: [
        {
          text: "File 1",
          state: { selected: true },
          icon: "jstree-file"
        },
        {
          text: "File 2",
          icon: "jstree-file"
        },
        {
          text: "Subfolder",
          state: { opened: false },
          icon: "jstree-folder",
          children: [],
          isFolder: true
        }
      ]
    }
  ];

  onSelectionChanged = (e: JQueryEventObject, data: any) => {
    console.group("Selection was changed");
    console.log(this);
    console.log(e);
    console.log(data);
    console.groupEnd();
  }

  onNodeMoved = (e: JQueryEventObject, data: JsTreeNodeMovedData) => {
    console.group("Node was moved");
    console.log(e);
    console.log(data);
    console.groupEnd();
  }
}

When binding a function to either selection-changed or node-moved instead of a lambda expression, please note that this inside your function is going to refer to the element vs your expected class instance. To avoid that bind with a proper context

<au-js-tree settings.bind="jstreeConfig"
            data.bind="data"
            selection-changed.bind="onSelectionChanged.bind($this)"
            node-moved.bind="onNodeMoved.bind($this)"></au-js-tree>

Acknowledgement

Thanks goes to Dwayne Charrington for his Aurelia-TypeScript starter package https://github.com/Vheissu/aurelia-typescript-plugin