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

vue3-tree-vue

v2.0.11

Published

A Simple vue3 project for rendering items in a tree.

Downloads

2,686

Readme

A Simple vue3 project for rendering items in a tree.

npm i vue3-tree-vue

<template>    
    <vue3-tree-vue :items="items" 
                   :isCheckable="false"  //Set to true if you want to get checkable items
                   :hideGuideLines="false"
                   @onCheck="onItemChecked"
                   @dropValidator="onBeforeItemDropped"
                   @onSelect="onItemSelected"
                   @onExpand="onItemExpanded"
                   >
      <!-- Applying some simple styling to tree-items -->
       <template v-slot:item-prepend-icon="treeViewItem" >
              <img src="./assets/folder.svg"
                   alt="folder"
                   v-if="treeViewItem.type === 'folder'"
                   height="20" width="20" />
       </template>
    </vue3-tree-vue>
</template>
import 'vue3-tree-vue/dist/style.css'; // remember to add this in your component or maint.[ts/js]
 
  setup() {
    const onItemChecked = (checkedItems: TreeViewItem[]) => console.log(checkedItems);
    const onItemSelected = (item: TreeViewItem) => console.log(item);
    const onBeforeItemDropped = (droppedItem: TreeViewItem, dropHost: TreeViewItem | undefined) => {
      // dropHost == undefined means dropping at the root of the tree.
      
      // Here you can specify any kind of drop validation you will like.
      // this function should return true if the drop operation is valid.

      if (dropHost.type !== playlist) return false
      return true;
    }
    const onItemExpanded = (expandedItem: TreeViewItem) => {
      //to use this feature properly you need to set lazyLoad property as true 
      //fetch data
      const lazyLoadedItems = fetchFromApi(...);
      expandedItem.children.push(...lazyLoadedItems)
    }
    const items = ref<TreeViewItem[]>([]); // define your tree items here.
    
    return {
      onItemChecked,
      onItemSelected,
      onBeforeItemDropped,
      onItemExpanded,
      items
    }
  }

Selectable Tree Items

image

Checkable Tree Items

image

Drag and Drop

GIF

Properties of the TreeView

| Property | Default | Description | | ----------- | ----------- |------------- | items | Empty array | An array of TreeViewItem. | | hideGuideLines | false | Determines the visibility of the guidelines | lazyLoad | false | Determines if the tree supports lazy-loading | isCheckable | false | Defines if items can be selected (one at a time) or selected (using a checkbox) | checkboxStyle | undefined | Defines the style to be applied to the checkboxes on the tree. | dropValidator | undefined | Specifies a callback of drag and drop rules.

Basic properties of each tree-node.

export interface TreeViewItem {
  name: string;
  id?: string | number;
  children?: TreeViewItem[];
  checked?: boolean;
  selected?: boolean;
  expanded?: boolean;
  disabled?: boolean;// When disabled, an item can neither be selected nor checked
  meta?: any;// provides meta-data of any type per node.
}

Event Handlers

| Events | Description | | ----------- | ------------- | onSelect | Callback function when an item is selected from the tree .Returns an ItemEventArgs. | onCheck | Callback function when an item is checked/unchecked from the tree. | onExpand | Callback function when an item is expanded (Can be used for lazy-loading) | onCollapse | Callback function when an item is collapsed

Styles

| Class | Description | | ----------- |------------- | selected-tree-item | Defines the style for the selectedItem

Slots

| Name | Description | | ----------- |------------- | item-prepend-icon | Defines the node's prepend icon. | item-prepend | Defines a slot to house content before the node's label. | item-expander | Defines a slot for custom expander implementations | item-append | Defines a slot for adding custom content after the item name | child-append | Defines a slot for adding a custom item after the last child

Classes

| Name | Description | | -------------|------------- | on-item-hover | Use in child-append and item-append slots to only show when the cursor is hovering on the node