Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(service): Add Whimsical and Figma services #123

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Tool uses Editor.js pasted patterns handling and inserts iframe with embedded co
- [CodePen](https://codepen.io) — `codepen` service
- [Pinterest](https://www.pinterest.com) - `pinterest` service
- [GitHub Gist](https://gist.github.com) - `github` service
- [Figma](https://www.figma.com/) - `figma` service
- [Whimsical](https://whimsical.com/) - whimsical service
- 👇 Any other [customized service](#add-more-services)



## Installation

Get the package
Expand Down Expand Up @@ -151,6 +151,7 @@ var editor = EditorJS({
```

#### Inline Toolbar

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

```javascript
Expand Down Expand Up @@ -180,7 +181,6 @@ var editor = EditorJS({
| height | `number` | embedded content height
| caption | `string` | content caption


```json
{
"type" : "embed",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/embed",
"version": "2.7.6",
"version": "2.7.7",
"keywords": [
"codex editor",
"embed",
Expand Down
18 changes: 16 additions & 2 deletions src/services.ts
thooams marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SERVICES: ServicesConfigType = {
return null;
}

if (!(paramsMap[name])) {
if (!paramsMap[name]) {
return null;
}

Expand Down Expand Up @@ -131,7 +131,6 @@ const SERVICES: ServicesConfigType = {
id: (ids) => ids.join('/embed/'),
},
instagram: {
//it support both reel and post
regex: /^https:\/\/(?:www\.)?instagram\.com\/(?:reel|p)\/(.*)/,
embedUrl: 'https://www.instagram.com/p/<%= remote_id %>/embed',
html: '<iframe width="400" height="505" style="margin: 0 auto;" frameborder="0" scrolling="no" allowtransparency="true"></iframe>',
Expand Down Expand Up @@ -183,6 +182,21 @@ const SERVICES: ServicesConfigType = {
width: 600,
id: (groups) => `${groups.join('/')}.js`,
},
whimsical: {
regex: /(https:\/\/)?whimsical.com\/(?:[a-zA-Z0-9\-]+\-)?([a-km-zA-HJ-NP-Z1-9]{16,22})(@[a-km-zA-HJ-NP-Z1-9]+)?/,
embedUrl: 'https://whimsical.com/embed/<%= remote_id %>',
html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
height: 300,
width: 600,
id: (ids) => ids[1]
},
figma:{
regex: /(https:\/\/www\.figma\.com\/.*)?/,
embedUrl: 'https://www.figma.com/embed?embed_host=share&url=<%= remote_id %>',
html: "<iframe height='450' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
height: 300,
width: 600
},
};

export default SERVICES;
27 changes: 27 additions & 0 deletions test/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,30 @@ describe('Miro service', () => {
})
});

describe('whimsical', () => {
it('should correctly parse URL got from a browser', () => {
const regularBoardUrl = 'https://whimsical.com/test-86ajy7vWEzYATvwFFvbwfA';
const event = composePasteEventMock('pattern', 'whimsical', regularBoardUrl);

embed.onPaste(event);

expect(patterns.whimsical.test(regularBoardUrl)).to.be.true;
expect(embed.data.service).to.be.equal('whimsical');
expect(embed.data.embed).to.be.equal('https://whimsical.com/embed/86ajy7vWEzYATvwFFvbwfA');
expect(embed.data.source).to.be.equal(regularBoardUrl);
});
});

describe('figma', () => {
it('should correctly parse URL got from a browser', () => {
const regularBoardUrl = 'https://www.figma.com/file/3BYrViWFPvfhbrpm1aO3ha/Untitled?type=design&node-id=0%3A1&mode=design&t=WutMRT9L8VJNEL5z-1';
const event = composePasteEventMock('pattern', 'figma', regularBoardUrl);

embed.onPaste(event);

expect(patterns.figma.test(regularBoardUrl)).to.be.true;
expect(embed.data.service).to.be.equal('figma');
expect(embed.data.embed).to.be.equal('https://www.figma.com/embed?embed_host=share&url=https://www.figma.com/file/3BYrViWFPvfhbrpm1aO3ha/Untitled?type=design&node-id=0%3A1&mode=design&t=WutMRT9L8VJNEL5z-1');
expect(embed.data.source).to.be.equal(regularBoardUrl);
});
});