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

@zstark/checked-tree-model

v1.2.1

Published

[![publish](https://github.com/PinghuaZhuang/checked-tree-model/actions/workflows/publish.yml/badge.svg)](https://github.com/PinghuaZhuang/checked-tree-model/actions/workflows/publish.yml) [![test](https://github.com/PinghuaZhuang/checked-tree-model/actio

Downloads

9

Readme

CheckedTreeModel

publish test license Commit Verison

一个树形结构数据的 checked 状态变化的数据模型. 返回一个 Diff 状态变化集合. 参考 antdTree 组件.

Example

Live Demo

🚀 Quick Start

import CheckedTreeModel from '@zstark/checked-tree-model';

const mock = {
  id: 0,
  name: 'title1',
  childList: [
    { id: 1, name: 'title2' },
    { id: 2, name: 'title3' },
  ],
};

const data = new CheckedTreeModel(mock);

data.setCheckedByIdReturnDiff(1);
// => { 0: { indeterminate: true }, 1: { checked: true } }
data.setCheckedByIdReturnDiff(2);
// => { 0: { checked: true, indeterminate: false }, 2: { checked: true } }

constructor

(options: Data, parent?: CheckedTreeModel) => void
export interface Data {
  id: string | number;
  pId: string | number;
  name: string;
  childList: Data[];
  className?: string;
  level: number;
  expand?: boolean;
}

export type Diff = {
  [P: string]: {
    indeterminate?: boolean;
    checked?: boolean;
  };
};

type EachCallback = (
  data: CheckedTreeModel,
  parent: CheckedTreeModel,
  index: number,
) => void;

type Undown = boolean; // 初始化的时候, 是否强关联(向下遍历).

Methods

  • isRoot: () => boolean. 是否是根元素
  • diff: () => { indeterminate?: boolean; checked?: boolean;} | undefined. 当前数据变化状态
  • setChecked: () => CheckedTreeModel. 选中当前数据.
  • setIndeterminate: () => CheckedTreeModel. 半选.
  • setCheckedByIdReturnDiff: (id?: Data['id'], value?: boolean, undown?: boolean) => {}
  • selectKeys: (keys: Ids, undown?: boolean) => Diff. 根据 ID 数组设置选中
  • getSelectKeys: () => Ids. 获取当前树所有选中的 ID.
  • clean: () => Diff. 清空当前树所有状态.
  • each: (fn: EachCallback) => void. 遍历子元素.
  • eachDeep: (fn: EachCallback) => void. 递归遍历子元素. 回调在递归前.
  • eachDeepAfter: (fn: EachCallback) => void. 递归遍历子元素. 回调在递归后.