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

@quarkd/core

v1.0.2

Published

Web components quark-element

Downloads

3

Readme

Quark Core

Quark Core 是一个优化 web components 开发体验的轻量级框架。部分实现思路参考Lit

使用

import QuarkElement, {
  Fragment,
  property,
  state,
  createRef,
  customElement
} from '@quarkd/core';
import style from './style.css';

@customElement({tag: 'quark-noticebar', style})
class QuarkNoticebar extends QuarkElement {
  @property()
  title: string = '';

  @property({type: Boolean})
  righthide: boolean = false;

  @state()
  count: number = 1

  rightSlotRef = createRef();

  handleRightClick = () => {
    this.$emit('rightclick');

    // 演示state装饰器
    this.count += 1;
  };

  handleRightSlotChange = () => {
    const { current } = this.rightSlotRef;
    if (current) {
      const hasChild = current.assignedNodes().length;
      current.style.paddingRight = hasChild ? '0px' : '11px';
    }
  };

  render() {
    return (
      <Fragment>
        <span>{this.title}</span>
        <span>{this.count}</span>
        <slot
          name="right"
          ref={this.rightSlotRef}
          onslotchange={this.handleRightSlotChange}
        >
          {!this.righthide && (
            <quark-icon
              name="right"
              size="15"
              onClick={this.handleRightClick}
            />
          )}
        </slot>
      </Fragment>
    );
  }
}

export default QuarkNoticebar;

API

  1. 装饰器:customElement(componentName: string) - 封装了customElements.define能力;
  2. 装饰器:property(options: Options)
    • observed
      • 类型:boolean
      • 默认值:true
      • 说明:标记当前属性是否接收外部的参数变化,会自动加入到observedAttributes数组中。
    • type
      • 值:Boolean | Number | String
      • 默认值:String
      • 说明:标记当前属性的类型,主要用于Boolean以及Number类型值的转换处理。
    • converter
      • 声明:(val: any, type?: typeof Boolean | typeof Number | typeof String) => any
      • 说明:从外部获取到属性时的值转换方法。
  3. 实例方法:render
    • 声明:() => string
    • 说明:返回的字符串用于赋值给shadowRoot.innerHTML,触发时机为QuarkElement基类的connectedCallback执行时。
  4. 生命周期方法:componentDidMount
    • 声明:() => void
    • 说明:connectedCallback触发时执行,此时组件dom已渲染完毕。相当于connectedCallback() { super.connectedCallback(); }
  5. 生命周期方法:shouldComponentUpdate
    • 声明:(propName: string, oldValue, newValue) => boolean
    • 说明:attributeChangedCallback触发时执行,用于控制当前属性变化是否导致组件更新渲染
  6. 生命周期方法:componentDidUpdate
    • 声明:(propName: string, oldValue, newValue) => void
    • 说明:attributeChangedCallback触发,render执行后触发,此时可拿到更新后的dom做相关操作
  7. 生命周期方法:componentWillUnmount
    • 声明:() => void
    • 说明:disconnectedCallback触发时、dom移除前执行,等同于disconnectedCallback() { super.disconnectedCallback(); }
  8. 实例方法:$on
    • 声明:(eventName: string, eventHandler: EventHandler, el?: Element) => void
    • 说明:支持为指定元素增加事件监听,并会在组件销毁时自动移除
  9. 实例方法:$emit
    • 声明:(eventName: string, customEventInit: CustomEventInit) => void
    • 说明:在当前组件中抛出自定义事件,相当于this.dispatchEvent(new CustomEvent(eventName, customEventInit))。

其他说明

  1. 无需再实现static get observedAttributes() {}
  2. 所有属性都建议增加默认值。
  3. 无需再手动执行 this.attachShadow({ mode: 'open' })。
  4. 旧的upgradeProperty方法能力已内置,代码中可以省略。
  5. Fragment的使用不是必须的,当你的render需要返回标签数组时使用,相当于react的<></>
  6. event需要全小写,例如ontouchstart、ontouchend、onclick