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

editorjs-embed-control

v1.0.2

Published

Embed Tool for Editor.js with input field

Downloads

204

Readme

Embed Block Tool for Editor.js

Provides Block tool for embedded content for the Editor.js.

Based on editor-js/embed.

Preview

Preview image

List of services supported

service — is a service name that will be saved to Tool's output JSON

Installation

Get the package

$ npm i editorjs-embed-control

Include module at your application

import EmbedControl from 'editorjs-embed-control';

Load from CDN

You can load a specific version of the package from jsDelivr CDN.

Require this script on a page with Editor.js.

<script src="https://cdn.jsdelivr.net/npm/editorjs-embed-control"></script>

Download to your project's source dir

  1. Upload folder dist from repository
  2. Add dist/embed.umd.js file to your page.

Usage

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

var editor = EditorJS({
  ...

  tools: {
    ...
    embed: EmbedControl,
  },

  ...
});

Available configuration

Enabling / disabling services

Embed Tool supports some services by default (see above). You can specify services you would like to use:

var editor = EditorJS({
  ...

  tools: {
    ...
    embed: {
      class: EmbedControl,
      config: {
        services: {
          youtube: true,
          twitch-video: false
        }
      }
    },
  },

  ...
});

Note that if you pass services you want to use like in the example above, others will not be enabled.

Add more services

You can provide your own services using simple configuration.

First, you should create a Service configuration object. It contains following fields:

| Field | Type | Description | | ---------- | ---------- | ----------- | | regex | RegExp | Pattern of pasted URLs. You should use regexp groups to extract resource id | embedUrl | string | Url of resource`s embed page. Use <%= remote_id %> to substitute resource identifier | html | string | HTML code of iframe with embedded content. embedUrl will be set as iframe src | height | number | Optional. Height of inserted iframe | width | number | Optional. Width of inserted iframe | id | Function | Optional. If your id is complex you can provide function to make the id from extraced regexp groups

Example:

{
  regex: /https?:\/\/codepen.io\/([^\/\?\&]*)\/pen\/([^\/\?\&]*)/,
  embedUrl: 'https://codepen.io/<%= remote_id %>?height=300&theme-id=0&default-tab=css,result&embed-version=2',
  html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
  height: 300,
  width: 600,
  id: (groups) => groups.join('/embed/')
}

When you create a Service configuration object, you can provide it with Tool`s configuration:

var editor = EditorJS({
  ...

  tools: {
    ...
    embed: {
      class: EmbedControl,
      config: {
        services: {
          youtube: true,
          coub: true,
          codepen: {
            regex: /https?:\/\/codepen.io\/([^\/\?\&]*)\/pen\/([^\/\?\&]*)/,
            embedUrl: 'https://codepen.io/<%= remote_id %>?height=300&theme-id=0&default-tab=css,result&embed-version=2',
            html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
            height: 300,
            width: 600,
            id: (groups) => groups.join('/embed/')
          }
        }
      }
    },
  },

  ...
});

You can take the configs from the original project: https://github.com/editor-js/embed/blob/master/src/services.js

Inline Toolbar

Editor.js provides useful inline toolbar. You can allow it`s usage in the Embed Tool caption by providing inlineToolbar: true.

var editor = EditorJS({
  ...

  tools: {
    ...
    embed: {
      class: EmbedControl,
      inlineToolbar: true
    },
  },

  ...
});

Localization

You can change the module name, labels and service names:

var editor = EditorJS({
  ...

  tools: {
    ...
    embed: EmbedControl,
  },
  i18n: {
    messages: {
      toolNames: {
        "Video": "Видео"
      },
      tools: {
        embed: {
          'Enter a link': 'Вставьте ссылку',
          'Enter a caption': 'Подпись',
          'Support services:': 'Поддерживаемые сервисы:',
          'youtube': 'YouTube',
          ...
        }
      }
    }
  },
  ...
});

Output data

| Field | Type | Description | ------- | -------- | ----------- | service | string | service unique name | source | string | source URL | embed | string | URL for source embed page | width | number | embedded content width | height | number | embedded content height | caption | string | content caption

{
  "type" : "embed",
  "data" : {
    "service" : "coub",
    "source" : "https://coub.com/view/1czcdf",
    "embed" : "https://coub.com/embed/1czcdf",
    "width" : 580,
    "height" : 320,
    "caption" : "My Life"
  }
}