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

pwaupdate

v1.0.0

Published

_Built with [lit-element](https://lit-element.polymer-project.org/)_

Downloads

11

Readme

pwa-update

Built with lit-element

What does it look like?

An image of what the component looks like

Supported Browsers

  • Edge
  • Chrome
  • Firefox
  • Safari

Using this component

Install

There are two ways to use this component. For simple projects or just to get started fast, we recommend using the component by script tag. If your project is using npm then we recommend using the npm package.

Script tag

  • Put this bit of code in your index.html
<script type="module" src="https://cdn.jsdelivr.net/npm/pwaupdate"></script>

<pwa-update></pwa-update>

NPM

  • Run npm install pwaupdate
  • import with import 'pwaupdate'

Then you can use the element <pwa-update></pwa-update> anywhere in your template, JSX, html etc. An example of using this component can be found here: https://pwa-update.glitch.me

API

Properties

| Property | Attribute | Description | Type | Default | | --------------- | --------------- | ------------------------------------------------------------- | -------- | ------------------------------------- | | updatemessage | updatemessage | Message that will be show to the user when there is an update | string | An update for this app is available |

Shadow Parts

If you need to style this component more comprehensively, you can use Shadow Parts to style both the update toast and the "ready to use offline" toast. To target these two elements you can use pwa-update::part(updateToast) and pwa-update::part(offlineToast) respectively. For more customizations in toast part, you can also target pwa-update::part(updateToastMessage) and pwa-update::part(updateToastButton) for message and button elements. For example, to make the background of the install button grey, I would need this CSS:

pwa-update::part(updateToast) {
  backround: grey;
}

Advanced Examples

Usage with typescript


// Types to be found in DefinitelyTyped sometime soon.
import "pwaupdate";

class YourClass extends RenderLib {
  ...

  get updateComponent(): PWAUpdate {
    return this.shadowRoot?.querySelector("pwa-update");
  }

  ...
}

Example with Component Reference (Web Components)

<template id="example">
  <style></style>
  ...
  <pwa-update></pwa-update>
</template>
customElements.define(
  "example",
  class Example extends HTMLElement {
    constructor() {
      super();
      let template = document.getElementById("example");
      let templateContent = template.content;
      this.shadowRoot = this.attachShadow({ mode: "open" }).appendChild(
        templateContent.cloneNode(true)
      );
      this.updateComponent = document
        .getElementsByTagName("el-example")[0]
        .shadowRoot.querySelector("pwa-update");
    }
  }
);

Example with Component Reference (Lit-Element)

// Using module import
import { LitElement, html, property, query } from "lit-element";
import "pwaupdate";

class Example extends LitElement {
  @query("installId") componentRef: HTMLElement;

  render() {
    return html`
      <body>
        <pwa-update id="installId"></pwa-update>
      </body>
    `;
  }

  interactionWithComponent() {
    // See the methods section
    this.componentRef.getInstalledStatus();
  }
}

Example with Component Reference (Fast-Element)

const template = html`
  <pwa-update ref('updateComponent')></pwa-update>
`

@customElement({ ... })
class Example extends FASTElement {
  @observable updateComponent: PWAUpdate | undefined;

  @volatile
  get updateComponent() {
    return this.shadowRoot.querySelector("pwa-update");
  }
}

Example of grabbing from the dom

<head>
  <script type="module" src="https://cdn.jsdelivr.net/npm/pwaupdate"></script>
</head>
<body>
  <pwa-update id="updateComponent"></pwa-update>
  <script async defer>
    const ref = document.getElementById("updateComponent);
  </script>
</body>

Example of programmatically creating the element

<head>
  <script type="module" src="https://cdn.jsdelivr.net/npm/pwaupdate"></script>
</head>
<body>
  <script async defer>
    var updateComponent = document.createElement("pwa-update");
    document.body.appendChild(updateComponent);
  </script>
</body>