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

magica-tree

v0.0.5

Published

シンプルな入れ替えのできるツリーUIを提供します

Downloads

8

Readme

MagicaTree

MagicaTree は リスト (ulli) を元にドラッグアンドドロップで操作できるツリーUIを構築します。

サンプル

使用方法

MagicaTree をインストールするコマンドを以下に記... そうと思いましたが、npmpublishしたら書きます。

ライブラリ利用方法

以下サンプル

    const data = {
        value: 'root',
        children: [
            {value: 'aaa', children: [
                {value: 'bbb', children: []},
                {value: 'ccc', children: []},
            ]},
            {value: 'ddd', children: []},
            {value: 'eee', children: []}
        ]
    };

    const tree = new MagicaTree.MagicaTree(
        document.getElementById('main'),
        function cnv (e, p) {
            const ti = new MagicaTree.TreeItem(e.value, undefined, p, e);
            for (const child of e.children) {
                cnv(child, ti);
            }
        },
        data
    );

    tree.addEventListener('drop', (evt) => {
        evt.detail.item.parent.data.children = evt.detail.item.parent.data.children.filter(e => e !== evt.detail.item.data);
        evt.detail.for.data.children.push(evt.detail.item.data);
        leave();
        tree.buildTree(data);
    });

ドキュメント

MagicaTree

コンストラクタ引数

| パラメータ | 型 | 説明 | |-------------|------------------------------------|------| | element | HTMLElement | ツリー表示を格納するHTML要素 | | converter | (data, parent) => Promise<void>; | データからツリー表示へ変換する関数 ※後述 | | data | Object | 初期データ |

  • converter 関数

データからツリー表示へ変換する関数を指定する必要があります。 この関数内では必ずTreeItemインスタンスを生成する必要があります。 (再帰的に呼び出されることを原則期待します。)

| パラメータ | 型 | 説明 | |-----------|--------------------------|------| | data | Object | 処理しているデータ | | parent | MagicaTree \| TreeItem | 自身の親TreeItemインスタンス(一番親のデータである場合はMagicaTreeインスタンス) |

イベント

  • イベントオブジェクト

基本的にはmagic-touchのイベントオブジェクトに以下を追加。

  • item: TreeItem: イベントが発せられたツリー要素
  • target: HTMLElement: イベントが発せられたツリー要素のHTMLElement
  • for: TreeItem: (holdoverholddropのみ) イベントを受けた(上に乗せられた、ドロップされた先)のツリー要素

メソッド

  • buildTree (data: Object): ツリーを再構築します。

TreeItem コンストラクタ引数

| パラメータ | 型 | 説明 | |-----------|-----------------------------|------| | inner | HTMLElement \| string | ツリーに表示する内容 | | opts | { directory: boolean } | オプション。(現時点では子要素を内包できるかのみ) | | parent | MagicaTree \| TreeItem | 親ツリー要素 | | data | Object | 紐づくデータ |

  • logo.png 背景素材はぱくたそ様より