• Stars
    star
    147
  • Rank 250,590 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Embed Tool for Editor.js

Embed Tool

Provides Block tool for embedded content for the Editor.js. Tool uses Editor.js pasted patterns handling and inserts iframe with embedded content.

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 --save @editorjs/embed

Include module at your application

import Embed from '@editorjs/embed';

Load from CDN

You can load specific version of package from jsDelivr CDN.

https://cdn.jsdelivr.net/npm/@editorjs/embed@latest

Then require this script on page with Editor.js.

<script src="..."></script>

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,
          coub: 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:

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: 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

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"
  }
}

About CodeX

CodeX is a team of digital specialists around the world interested in building high-quality open source products on a global market. We are open for young people who want to constantly improve their skills and grow professionally with experiments in cutting-edge technologies.

🌐 Join 👋 Twitter Instagram
codex.so codex.so/join @codex_team @codex_team

More Repositories

1

awesome-editorjs

🤩 A curated list of awesome Editor.js tools, libraries and resources.
2,103
star
2

editorjs-php

PHP backend for Editor.js
PHP
242
star
3

image

Image Block for Editor.js
TypeScript
233
star
4

table

Table constructor for Editor.js
JavaScript
123
star
5

header

Header Tool for Editor.js 2.0
TypeScript
99
star
6

link

Link Tool for Editor.js 2.0
JavaScript
87
star
7

marker

Marker Tool for Editor.js 2.0
JavaScript
74
star
8

code

Code Tool for Editor.js 2.0
TypeScript
69
star
9

attaches

File attachments Block for the Editor.js
JavaScript
61
star
10

checklist

Checklist Tool for Editor.js
JavaScript
56
star
11

list

List Tool for Editor.js 2.0
JavaScript
55
star
12

raw

Raw HTML tool for Editor.js
JavaScript
55
star
13

simple-image

Simple Image Tool for Editor.js 2.0
JavaScript
52
star
14

nested-list

Multi-leveled lists for the Editor.js.
TypeScript
44
star
15

inline-code

Inline-Code Tool for Editor.js 2.0
TypeScript
43
star
16

personality

Personality Tool for Editor.js
JavaScript
42
star
17

paragraph

Paragraph Tool for Editor.js 2.0
TypeScript
41
star
18

quote

Quote Tool for Editor.js 2.0
TypeScript
36
star
19

delimiter

Delimiter plugin for Editor.js 2.0
TypeScript
34
star
20

link-autocomplete

An upgraded version of base inline link tool with your server's search.
JavaScript
28
star
21

simple-image-tutorial

Final result of guide series learning how to create own Block Tool
JavaScript
26
star
22

create-tool

Single command Editor.js Tool generator
TypeScript
25
star
23

warning

Warning Tool for CodeX Editor 2.0
JavaScript
23
star
24

underline

Inline tool for underlining text fragments
TypeScript
14
star
25

text-variant-tune

Block Tune for text variants: Call-out, Citation, Details
JavaScript
11
star
26

document-model

❗️WIP❗️
TypeScript
10
star
27

footnotes-tune

Footnotes Block Tune for Editor.js
TypeScript
8
star
28

translate-inline

Translate Inline Tool for Editor.js
TypeScript
5
star
29

spoiler

Work in progress
JavaScript
5
star
30

audio

Work in progress
3
star
31

dev-tools

TypeScript
2
star
32

nft

Embed NFTs
TypeScript
2
star
33

.github

1
star