Socket
Socket
Sign inDemoInstall

embed-ui

Package Overview
Dependencies
911
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    embed-ui

Embed for Editor.js including UI for menus and input prompts


Version published
Weekly downloads
4
decreased by-87.5%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Embed UI Tool

Provides Block tool for embedded content for the Editor.js. Tool uses Editor.js pasted patterns handling and inserts iframe with embedded content. Forked from the Editorjs Embed Tool, and updated to show tool in toolbox and include an input prompt for better UI.

List of services supported

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

Installation

Install via NPM

Get the package

npm i embed-ui

Include module at your application

import Embed from "embed-ui";

Usage

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

var editor = EditorJS({
  ...

  tools: {
    ...
    embed: Embed,
  },

  ...
});

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: Embed,
      config: {
        services: {
          youtube: true,
          loom: true
        }
      }
    },
  },

  ...
});

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:

FieldTypeDescription
regexRegExpPattern of pasted URLs. You should use regexp groups to extract resource id
embedUrlstringUrl of resource`s embed page. Use <%= remote_id %> to substitute resource identifier
htmlstringHTML code of iframe with embedded content. embedUrl will be set as iframe src
heightnumberOptional. Height of inserted iframe
widthnumberOptional. Width of inserted iframe
idFunctionOptional. 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: Embed,
      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/')
          }
        }
      }
    },
  },

  ...
});
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: Embed,
      inlineToolbar: true
    },
  },

  ...
});

Output data

FieldTypeDescription
servicestringservice unique name
sourcestringsource URL
embedstringURL for source embed page
widthnumberembedded content width
heightnumberembedded content height
captionstringcontent 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"
  }
}

Keywords

FAQs

Last updated on 06 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc