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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ts-medialibrary

v1.2.1-alpha

Published

A client framework and server agnostic Media library Web Component made with [vue3](https://v3.vuejs.org).

Readme

Media Library Web Component

A client framework and server agnostic Media library Web Component made with vue3.

Installation

Install ts-medialibrary with npm

  npm install ts-medialibrary

Usage Example

Javascript

<form>
  <ts-medialibrary
      multiple
      title="Library Demo For Github"
      url="http://dummy.dev/media"
    ></ts-medialibrary>
    <div id="fileinput"></div>
</form>

<script src="node_modules/ts-medialibrary/dist/ts-medialibrary.js"></script>
<script>
    customElements.whenDefined("ts-medialibrary").then((c) => {
      const el = document.querySelector("ts-medialibrary");

      if(el){
        el.addEventListener("updated", function (e) {
          const payload = e.detail[0];

          //appending hidden input insdie form
          document.getElementById("fileinput").innerHTML = payload.html;
        });
      }
      
    });
</script>

Vue

  import 'ts-medialibrary/dist/ts-medialibrary.js';

  <ts-medialibrary url="REST_URL_HERE" @updated="onSelectionChanged"></ts-medialibrary>

React

You can either add ref to the ts-medialibrary and listen just like with js or can wrap and make new HOC react component.

import 'ts-medialibrary/dist/ts-medialibrary.js';

const MediaLibrary = ({ url, onChange }) => {
  const ref = useRef();


  useLayoutEffect(() => {
    const handleChange = customEvent => onChange(customEvent.detail[0]);

    const { current } = ref;

    current.addEventListener('updated', handleChange);

    return () => current.removeEventListener('updated', handleChange);
  }, [ref]);

   

  return (
    <ts-medialibrary
      ref={ref}
      url={url}
    />
  );
};

API Reference

Client

| Props | Type | Default | Description | | :-------- | :------- | :------- | :-------------------------------- | | url | string | none | Required. REST Url to fetch and upload media | | uid | string | default | Unique identifer required for multiple instances in same page. | | label | string | Select File(s) | Upload Button Label | | title | string | Media Library | Library Modal Heading | | udpate-label | string | Click To Change | Upload Button Label after selections are made | | choosen | string | None | Comma separated id to preselect media. | | can-remove | string, boolean, number | 0 | Allow delete action if true | | blocking | string, number, boolean | 0 | If true than backdrop blocks the UI and modal stays open when clicking on it | | input-name | string | files[] | input name which is used to return html string on update | | input-key | string | id | key from media object to be used as input value | | multiple | string, boolean, number | 0 | Allow multiple selection and upload | | preview-link | string, boolean, number | 1 | Open selected media in new tab | allow-files | boolean, number | 0 | By default only images are allowed, Passing value of 1 will allow upload of any files defined in accept prop | | accept | string | "image/*, audio/*, video/*, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, .pdf, .doc, .docx, .csv, .txt | File types to accept when allow-files=1. Only for clientisde. For server validation you have to use your own. | | limit | number | 50 | Number of max items to display in the library. Your server can return 100s of items but library will only show limit items. To see the remaining items, either have to search or sort. |

Emits

| Event | Payload | Description | | :-------- | :------- | :----- | | updated | selected: media[] | Arry of selected media {id, url, thumb_url}[] | | html: string | Hidden input string with input-name as name and value mapped to media[input-key] |

Events are dispatched as native CustomEvents on the custom element. Additional event arguments (payload) will be exposed as an array on the CustomEvent object as its detail property. const payload = e.detail[0];

Server

Server Api Reference.

To test the library there is a default solution provided for laravel, You have to install one of my other package Media Library Package which comes with all required url actions.

Get all items

  GET /PROPS_URL
Response
{"items": "MediaResourceCollection[]", "success": 1}

Upload item

  POST /PROPS_URL

| Body | Type | Description | | :-------- | :------- | :-------------------------------- | | files[] | HTTPFile | Required. array of files | | allow_files | number(0, 1) | If the upload should support only image or any files. |

Response
{"items": "UploadedMediaResourceCollection[]", "success": 1, "message": "UPLOADED SUCCESS MESSAGE"}

Delete item

  DELETE /PROPS_URL/${id}

| Parameter | Type | Description | | :-------- | :------- | :-------------------------------- | | id | string | Required. Id of item to delete |

Response
{ "success": 1, "message": "DELETED MESSAGE"}

Error Response

{ "error": 1, "message": "ERROR_MESSAGE"}

Customization and Theming

| CSS Variable | Default | Description | | :-------- | :------- | :-------------------------------- | | --tml-color-primary-rgb | 99, 102, 241 | Primary color RGB | | --tml-color-danger-rgb | 255, 0, 0 | Primary color RGB | | --tml-color-success | green | Success Color | | --tml-color-secondary | rgb(249, 250, 251) | Secondary Color | | --tml-color-grey | grey | Grey Color | | --tml-color-light | #bbbbbb | Light Color | | --tml-color-lighter | #cccccc | Lighter Color | | --tml-modal-z-index | 100 | Z-Index for modal | | --tml-modal-content-z-index | 10| Z-Index for modal content | |--tml-modal-animation-duration | 0.3s | Modal open animation duration | |--tml-modal-background-color |rgba(30, 30, 30, 0.8)| Modal background color | |--tml-modal-width |fit-content| Modal width | |--tml-modal-min-width |500px| Modal min width | |--tml-modal-max-width |100vw| Modal max width | |--tml-modal-height |80%` | Modal height |

There are a lot more variables which will be updated soon.

Tech Stack

Client: Vue3, Typescript, SCSS

Demo

SQ11g1JduD7-z-0-y-647a0fb8cfa57536f50cfc49

Acknowledgements