Git Product home page Git Product logo

embed's Introduction

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

  • Facebook - facebook service
  • Instagram - instagram service
  • YouTube - youtube service
  • Twitter - twitter service. (official twitter api is used for render, no need to use twitframe)
  • Twitch - twitch-video service for videos and twitch-channel for channels
  • Miro - miro service
  • Vimeovimeo service
  • Gfycatgfycat service
  • Imgurimgur service
  • Vine - vine service. The project is in archive state now
  • Aparat - aparat service
  • Yandex.Music - yandex-music-track service for tracks, yandex-music-album for albums and yandex-music-playlist for playlists
  • Coubcoub service
  • CodePencodepen service
  • Pinterest - pinterest service
  • GitHub Gist - github service
  • 👇 Any other customized service

Installation

Get the package

yarn add @editorjs/embed

Include module at your application

import Embed from '@editorjs/embed';

Optionally, you can load this tool from CDN JsDelivr CDN

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

embed's People

Contributors

abhii5496 avatar dependabot[bot] avatar dependentmadani avatar douglasmiranda avatar fishchev avatar gohabereg avatar haris2k avatar hortopan avatar jefcolbi avatar kentarohorie avatar kornarakis avatar nespecc avatar parterburn avatar polinashneider avatar robonetphy avatar smokietr avatar takky94 avatar talyguryn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

embed's Issues

Add Github gist to editor

Can you please add an option to embedd Github gist and with read-only option enabled,
Plugins avaibale for GitHub gist does not provide an read-only option

Embed as new block

Would you consider a drastic change that embed would not be inline but block element? I think it would be logical because the link is converted into some preview which is block. It would work this way:

  • There should be a button in Plus toolbar to add new Embed block.
  • When user types or pastes the supported URL, the current paragraph will be split and new Embed block will be inserted

Thank you for consideration

Imgur embed link leads to 404

The generated embed link is like http://imgur.com/{id}/embed

but the actual embed link should look like https://imgur.com/a/{id}/embed?pub=true&;w=540

Kindly look into this issue soon.

How to set a Editor template?

Hi I am new to editor.js and I am amazed by its potential to compete with Gutenberg. I have read the doc, and it seems like that block template is not a thing in Editor.js at the moment.

IMO this features is essential if we need to build a more complex editor(e.g Form, Profile entry), which it can limit how user can interact with the form.

Output format: Are width/height always integers, or can they be floats?

In the output format, are width and height guaranteed to always be integers, or can they be floating point numbers?

Context: I'm a back-end .NET developer needing to parse Editor.js documents. Back-end deserialization/parsing in strongly typed languages requires me to choose to deserialize to either int (the simplest and most constrained) or float (the most general, but unnecessary if it's guaranteed to always be an integer). If these properties are guaranteed to always be int, then that guarantee should ideally be added to the readme to ensure it is formalized and kept in the future.

Genially custom embed is a no no

Long live the devs!

I have designed a custom service to embed genially presentation as following:

genially: { regex: /https?:\/\/view.genial.ly\/(\w+)\/?(\w+(-[\w]+)+)?/, embedUrl: 'https://view.genial.ly/<%= remote_id %>', html: "<div style='position: relative; padding-bottom: 56.25%; padding-top: 0; height: 0;'><iframe frameborder='0' style='width: 100%; height: 100%;' type='text/html' allowscriptaccess='always' allowfullscreen='true' scrolling='yes' allownetworking='all'></iframe></div>" }

Unfortunately there is no joy.

I also introduce a block dynamically by the time I import a record somewhere in the code where I ingest records from a CSV:

if (id) { content.blocks.push({ "id": nanoid(10), "type": "embed", "data": { "service": "genially", "source":https://view.genial.ly/${id}`,
"embed": https://view.genial.ly/${id},
"caption": title
}
});
}`

And it doesn't show neither.

Is there something slipping my attention or I just bumped into a dodo?

These are typically genially links:

thank you.

Output format: Which properties (if any) can be null omitted?

For a valid embed block, can any of the service, source, embed, width, height, or caption properties under any circumstances (now or in the future) be null or omitted? Are any of the aforementioned properties guaranteed to always be present and non-null for this block to be valid?

Context: I'm a back-end .NET developer needing to parse Editor.js documents. The readme lists all of the aforementioned properties but does not explicitly guarantee that they will always be present and non-null. Back-end deserialization/parsing in strongly typed languages would be easier with some guarantees about which properties can and can not be null/omitted. (Ideally, any such guarantees should be added to the readme to ensure they are formalized and kept in the future.)

window is not defined

I just install and import it through my component, not config or using any parameters yet.
And the react error popup shows the 'ReferenceError: window is not defined' message.
file-path: ~/node_modules/@editorjs/embed/dist/bundle.js
and my dependencies:
{
"@editorjs/checklist": "^1.3.0",
"@editorjs/code": "^2.7.0",
"@editorjs/delimiter": "^1.2.0",
"@editorjs/editorjs": "^2.23.2",
"@editorjs/embed": "^2.5.1",
"@editorjs/header": "^2.6.2",
"@editorjs/image": "^2.6.2",
"@editorjs/inline-code": "^1.3.1",
"@editorjs/link": "^2.4.0",
"@editorjs/list": "^1.7.0",
"@editorjs/marker": "^1.2.2",
"@editorjs/paragraph": "^2.8.0",
"@editorjs/quote": "^2.4.0",
"@editorjs/raw": "^2.3.0",
"@editorjs/simple-image": "^1.4.1",
"@editorjs/table": "^2.0.1",
"@editorjs/warning": "^1.2.0",
"autoprefixer": "^10.4.4",
"next": "12.1.4",
"postcss": "^8.4.12",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-editor-js": "^2.0.6",
"react-icons": "^4.3.1"
}

Please check it and notify me if I miss any steps or you found a solution.
Many thanks,

twitch-video & twitch-channel return errors.

It seems that embedding for Twitch has gone as twitch-video & twitch-channel return the following:
Security Error: Content at chrome://browser/skin/privatebrowsing/aboutPrivateBrowsing.css may not load data from blob:null/9c869394-8ec8-4d19-9d1e-33bc6e8e449a.

Aparat service does not work

I wanna use the Aparat service. When I passed this URL into editor content https://www.aparat.com/v/rE9gU the iframe doesn`t inject into my body.

[Feature] use embed as multiple type

like this:

video: {
    class: Embed,
    inlineToolbar: true,
    config: {
        // video service
    }
},
music: {
    class: Embed,
    inlineToolbar: true,
    config: {
        // music service
    }
},

Why this regex for Redgifs can't work?

Trying to add a support for NSFW version of gfycat

`redgifs: {

regex: /(?:https://)?(?:www.)?redgifs.com/watch/([a-zA-Z]+)$/gm,
embedUrl: 'https://redgifs.com/ifr/<%= remote_id %>',
html: "<iframe height='360' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
width: 640, height: 360
}`

gfycat itself works

Config doesn't pass down with latest EditorJS version (2.20.2)

When I upgrade to the latest EditorJS version (2.20.2) the config settings do not get passed down to the Embed tool (all services are turned on and my custom services do not work). I don't know if this is an issue with EditorJS or if something needs to be upgraded in the embed package.

Happy to help debug anyway I can!

Parcel error

...\node_modules\@editorjs\embed\dist\bundle.js:1:5165: Unexpected token (1:5165)

I get this error when I

import Embed from '@editorjs/embed';

and run

parcel serve main.js

package.json:

{
  ...
  "devDependencies": {
    "@editorjs/editorjs": "^2.17.0"
  },
  "dependencies": {
    "@editorjs/embed": "^2.3.1",
    "@editorjs/header": "^2.4.1",
    "@editorjs/list": "^1.4.0"
  }
}

How to insert() embed programmatically?

For example, imagine typing the source URL in a text input, then feeding it to the insert() method:

editor.blocks.insert('embed', {source: url}, {}, index, true)

Of course, that won't work because the service and embed URL have not been set.

How can you insert an embed block based just on the source URL, without parsing the service and embed URL yourself?

Custom services not working

Hello,
I'm using this plugin for one of my client. I tried adding a custom service, fairly simple, but it does not seem to be taking into account. I tried everything, re-wrote many times the regex. The exemple on the readme seems to work only because it is already included in the default services.

Here is my configuration:

airtable: {
  regex: /https?:\/\/airtable\.com\/([a-zA-Z0-9]*)/,
  embedUrl: "https://airtable.com/embed/<%= remote_id %>",
  html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
},

Is anyone else having same trouble?

`Cannot read property 'updateCurrentInput' of undefined` after updating to 2.4.0

Working on a project which had been using 2.3.1, with @editorjs/editorjs 2.19.1. Yesterday I updated the Embed tool to 2.4.0, and started seeing this error being thrown when clicking in the Editor instance in the blank space after the last paragraph:

Uncaught TypeError: Cannot read property 'updateCurrentInput' of undefined
    at y.value (editor.js?9336:2)
    at k.value (editor.js?9336:2)
    at HTMLDocument.eval (editor.js?9336:2)
value @ editor.js?9336:2
value @ editor.js?9336:2
eval @ editor.js?9336:2

Clicking on existing text in the Editor instance does not throw this error.

After reverting to @editorjs/embed to 2.3.1 I do not see the error locally any more.

Adding gist github service

Hi, i am trying to add gist github service but it is not working. This is what i tried

'github': {
              regex: /https?:\/\/gist.github.com\/([^\/\?\&]*)\/([^\/\?\&]*)/,
              embedUrl: 'https://gist.github.com/<%= remote_id %>',
              html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
              height: 300,
              id: (groups) => groups.join('/')
          }

What am i doing wrong?

Service config doesn't work !!!

I did a lot of tests with config. And looks like it doesn't work.
It only supports default services from official list.

A year ago: I added Twitch clips support but it can no longer work.

Export the services configuration

In order to avoid repeating too much when overriding a service’s configuration only partially, it’d be great to be able to extend the bundled configuration:

import Embed, { services } from '@editorjs/embed'

// …

embed: {
    class: Embed,
    config: {
        services: {
            vimeo: {
                ...services.vimeo,
                html: `<div class="vimeo-wrap">${services.vimeo.html}</div>`
            }
        }
    }
}

Create a Github service

it sometime comes to case when some one also want to embed github's link and it will be nice to also have one service for github

editor-js is returning wrong output data when using embed

After installing editor-js/embed and adding it to tools, editor-js is still returning incorrect data.
It is recognizing embedded elements as paragraphs, returning type: "paragraph" and, text and level keys in the data object instead of:

{
  "type" : "embed",
  "data" : {
    "service" : "...",
    "source" : "...",
    "embed" : "...",
    "width" : ***,
    "height" : ***,
    "caption" : "..."
  }

Urls over a set length won't work

I'm tríing to get embed to work but I noticed that some urls won't work. I think it has something to do with url length. For reproduction of the issue use following config and Uel:

embed:
{
class: Embed,
inlineToolbar: itb,
config:
{
services:
{
falstad:
{
regex: /https?://(www.)?falstad.com/circuit/circuitjs.html?ctz=(.*)/,
embedUrl: 'https://www.falstad.com/circuit/circuitjs.html?ctz=<%= remote_id %>',
html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
height: 400,
width: 800,
id: (groups) => groups[1]
},
}
}
},

http://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsAoANxAFowU8RcbX3Ox2UcBSpIq46AnoATVnioCUtfoKXSApgDMAhgFcANgBd6AJxDFC4QRa6QeCuPQDuchYLYcrSyM+VfzlopQvjbcvJ5hPswoCJZhMYGCCiLU4lCSMlx4PCgoPNjZ-mpaekaZ2NhxdlyVIGicxToGxrIVlvU1iUqNpS1Z+dUFOXl1IBpNZS5t-kP+PlO1YbORvglFeCreqxvrDfjBLhx7nNMd83Wxtjk7K4c31Ud1I+ePufmFbwf9-jQ2QefLaq-Kr2UwUGg8IIICFXIRgRw0SDYVg0fgYSzyOqIoQoAD6hBouMguMRpFxCCJsApxLxeIYiORiIU6IonjyaRQYHxhOJpOI5MpkGpuNpXIYLmhkMEwLmvklsJlKyAA

Halfway through the url it works well (meaning it will properly insert the iframe with the incomplete link) but the while url does not insert the embed iframe.

do not encode embed url &

my embedUrl is: //music.163.com/outchain/player?type=2&height=66&id=<%= remote_id %>,

and get content is://music.163.com/outchain/player?type=2&amp;height=66&amp;id=22793199

Unable to save html in data blocks

When I try to update data like

this.data = {
    html: "<div><p>TESTING</p></div>"
}

Block is updated as

{
 html: "TESTING"
}

It doesn't update whole html.

Disable caption

Nice plugin. Is there a way how to disable a caption? I do not want it in my editor. Thank you

image

Embed not visible in toolbox

Tried to include the embed plugin in toolbox, Everthing is working without errors, but its not visible in the toolbox.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.