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

lb-vue-tree

v1.3.2

Published

Vue2.js boostrap 4.0 tree with local and serverside loading, menu and checkbox option

Downloads

55

Readme

Screenshot

Description

Install

npm install lb-vue-tree --save

Include plugin in your main.js file.

import Vue from 'vue'
import lbVueTree from 'lb-vue-tree';
Vue.component('lb-vue-tree', lbVueTree);

Usage

Local data (or complete serverside load)

In this example, if you have a call to server, or static data that is smaller and has all the nodes inside, you can fetch data once and use it in a tree.

template code for local data

<template>
    <lb-vue-tree v-model="data" v-on:itemclick="itemClick" display-field="text">
        <template slot="rootitem"slot-scope="{item, parent}">
            <span>Root item</span>
        </template>
        <template slot="menu" slot-scope="{item, parent}">
            <ul>
                <li>New</li>
                <li>Edit</li>
            </ul>
        </template>
        <template v-slot:itemcontent="{item}">
            <div class="item-inputs">
                Min: <input type="text" v-model="item.text">
                Max: <input type="text">
                Active: <input type="checkbox">
            </div>
        </template>
    </lb-vue-tree>
</template>

script code for local data

export default {
    data(){
        return {
            data: [{
                id: '1',
                text: 'test',
                children: [{
                    id: '2',
                    text: 'child test'
                }]
            }]
        }
    },
    methods: {
        itemClick(item, parent) {

        }
    }
};

Remote data (server side data), fetching node by node, also draggable support

In this case you can load server side data only for singe node, so for example you will load only initial root level, then by clicking on the nodes your assigned method will be called to fetch "ONLY" that node children

Method for fetching node data MUST be a promise, callbacks are not supported

template code for server side data

<template>
    <lb-vue-tree v-model="data" :async-method="getData" v-on:itemclick="itemClick" :draggable="true" v-on:dragend="dragEnd" display-field="username">
        <template slot="rootitem">
            <span>Root item</span>
        </template>
        <template slot="menu" slot-scope="{item, parent}">
            <ul>
                <li>New</li>
                <li>Edit</li>
            </ul>
        </template>
    </lb-vue-tree>
</template>

There are two optional slots to use: "rootitem": used if you wan't to display root item of the tree in case your tree data does not have it and you need a starting point "menu": if you need a menu on right click, you can add it here, there are also two arguments, item and parent passed to menu slot

script code for remote data

export default {
    data(){
        return {
            data: []
        }
    },
    async created()
    {
        //make an initial load of data
        this.data = await this.getData(null);
    },
    methods: {
        itemClick(item) {

        },
        dragEnd(data)
        {
            //data.start holds the item you are dragging
            //data.end holds the item dragged on
            //data.position holds the postion related to end position (upper, center, lower)
            console.log(data.start, data.end, data.position);
        },
        async getData(item, parent)
        {
            if(item != null)
            {
                //fetch data from server for specific node based on data from item, for example:
                return await axios.get('/getTreedata?id='+item.id)
            }
            else
            {
                return await axios.get('/getTreedata')
            }
        }
    }
};

Available settings

| Property | Type | Required | Description | | :---------------- | :-- | :-- | :-- | | value (v-model) | Array | * | value array | | display-field | string | | Display field key from value item object (Defaults to text) | | display-func | function | | If you want to combine multiple fields to display text, you can specify custom function which receives one argument (item) | | children-field | string | | Children field key (key which holds descendants) from value item object (Defaults to children) | | children-expanded-field | string | | If you want to show this branch already expanded set this to boolean field (Defaults to expanded) | | has-children-field | string | | In case of async tree, if you already know if that branch has children set the filed that holds the boolean here | | checkbox | boolean | | If you want to enable checkboxes in the tree (Defaults to false) | | checked-field | string | | Key from value which holds boolean state if the item is checked or not | | async-method | function | | If you want to use serverside fetching node by node (in case of big tree) method receives item as argument | | draggable | boolean | | If you want to enable drag and drop, put boolean true here (not string) | | clickonopen | boolean | | If you want to enable item click event on openning of the item | | showvalue | boolean | | If you have a display function and you don't wan't to display value also, put this to false | | showsearch | boolean | | If you want to have search boxes for each level enabled | | searchPlaceholder | string | | String to use for search placeholder on each item, you can use {level} specifier inside string |

Available events

| Event | Arguments | Description | | :---------------- | :-- | :-- | | itemclick | item, parentItem | item from data array you clicked on and it's parent | | itemrightclick | item, parentItem | item from data array you clicked on with right mouse button and it's parent | | dragend | data | Function to be called when drag ends, one argument, object with start, end and position attributes |