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

@stegopop/media-picker

v1.0.1

Published

Media Picker Tool for EditorJS

Downloads

5

Readme

Media Picker

https://github.com/user-attachments/assets/cb45ba8c-40b1-4ff6-b970-b05fe2803a39

Installation

Install via NPM

Get the package

npm i --save-dev @stegopop/media-picker
yarn add -D @stegopop/media-picker

Load from CDN

You can use package from jsDelivr CDN.

<script src="https://cdn.jsdelivr.net/npm/@stegopop/media-picker"></script>

Usage

Add a new Tool to the tools property of the Editor.js initial config.

var editor = EditorJS({
  ...
 
  /**
   * Tools list
   */
  tools: {
    mediaPicker: {
      class: MediaPicker,
      config: {
        endpoint: 'https://localhost:8080/api/media/search',
        queryParam: 'search',
        pageParam: 'page',
      }
    }
  },
  
  ...
});

Config Params

Search requests will be sent to the server by GET requests with 2 query string params. One for searching, and another for paging.

List of server connection params which may be configured.

| Param | Required | Default | Description | |--------------|----------|----------|-------------------------------------------------------| | endpoint | Yes | null | URL of the server's endpoint for getting image media. | | queryParam | No | 'search' | Param name to be sent with the search string. | | pageParam | No | 'page' | Param name to be sent with the page string. |

Server response data format

For endpoint requests server must answer with a JSON containing following properties:

  • success (boolean) — state of processing: true or false
  • files ({url: string, alt: string|null, filename: string, extension: string}) — an array of found files. Each file must contain a url, filename, and extension params.
  • page (int) - the current page.
  • totalPages (int) - the total number of pages resulting from the search.

Content-Type: application/json.

{
  "success": true,
  "files": [
    {
      "url": "https://localhost:8080/url/to/your/image.webp",
      "alt": null,
      "filename": "image",
      "extension": "webp"
    },
    {
      "url": "https://localhost:8080/url/to/your/image2.png",
      "alt": null,
      "filename": "image2",
      "extension": "png"
    }
  ],
  "page": 1,
  "totalPages": 1
}

Output data

Everything you need to render the image will be in the output data. You may use this data to create your own html, or use the html or htmlWithCaption that are also provided.

{
    "type" : "mediaPicker",
      "data" : {
          "src" : "https://localhost:8080/url/to/your/image.webp",
          "alt" : "",
          "filename" : "image",
          "extension" : "webp",
          "caption" : "My caption.",
          "html" : "<img class=\"mediapicker-image\" src=\"https://localhost:8080/url/to/your/image.webp\" alt=\"\" data-filename=\"20230205_142334\" data-extension=\"webp\">",
          "htmlWithCaption" : "<figure class=\"mediapicker-figure\"><img class=\"mediapicker-image\" src=\"https://localhost:8080/url/to/your/image.webp\" alt=\"\" data-filename=\"image\" data-extension=\"webp\"><figcaption>My caption.</figcaption></figure>"
      }
}

I18n

There are a few phrases to be translated.

UI items:

  • Media Library - The name of the tool in the editor menu.
  • Search — Placeholder for the search input field.
  • Caption — Placeholder for the caption input field.
  • View Details - Tooltip text when hovering over the library preview expand button.
  • Select New File - Tooltip text when hovering over the replace button after selecting an image.
  • tab - The text inside the tab key when a caption has pulled a suggestion from available alt text.
  • Filename - A label in the expanded preview to show details about the file.
  • Alt Text - A label in the expanded preview to show details about the file.
  • First - Button text for going back to the first page.
  • Last - Button text for going to the last page.

Error messages:

  • Cannot process search request because of — Message before error's text in notification for a bad server response.
  • Server responded with invalid data — Notification text for a bad server response.
i18n: {
  messages: {
    toolNames: {
      "Media Picker": "Image Select"
    },
    tools: {
      "mediaPicker": {
        'Search': 'Buscar',
        'Caption': 'Subtítulo',
        'View Details': 'Ver Detalles',
        'Select New File': 'Seleccionar nuevo archivo',
        'tab': 'Tab',
        'Filename': 'Nombre del archivo',
        'Alt Text': 'Texto alternativo',
        'First': 'Primera',
        'Last': 'Última',
        'Cannot process search request because of': 'No se puede procesar la solicitud de bùsqueda debido a',
        'Server responded with invalid data': 'El servidor respondió con datos no válidos',
      }
    }
  }
},