Skip to content

Commit 863834c

Browse files
authored
Merge pull request #123 from thooams/master
feature(service): Add Whimsical and Figma services
2 parents 2152eb2 + b0c39bd commit 863834c

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ Tool uses Editor.js pasted patterns handling and inserts iframe with embedded co
2626
- [Pinterest](https://www.pinterest.com) - `pinterest` service
2727
- [GitHub Gist](https://gist.github.com) - `github` service
2828
- [Reddit](https://www.reddit.com/) - `reddit` service
29+
- [Figma](https://www.figma.com/) - `figma` service
30+
- [Whimsical](https://whimsical.com/) - whimsical service
2931
- 👇 Any other [customized service](#add-more-services)
3032

31-
32-
3333
## Installation
3434

3535
Get the package
@@ -152,6 +152,7 @@ var editor = EditorJS({
152152
```
153153

154154
#### Inline Toolbar
155+
155156
Editor.js provides useful inline toolbar. You can allow it\`s usage in the Embed Tool caption by providing `inlineToolbar: true`.
156157

157158
```javascript
@@ -181,7 +182,6 @@ var editor = EditorJS({
181182
| height | `number` | embedded content height
182183
| caption | `string` | content caption
183184

184-
185185
```json
186186
{
187187
"type" : "embed",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/embed",
3-
"version": "2.7.7",
3+
"version": "2.8.0",
44
"keywords": [
55
"codex editor",
66
"embed",

src/services.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ const SERVICES: ServicesConfigType = {
140140
id: (ids) => ids.join('/embed/'),
141141
},
142142
instagram: {
143-
//it support both reel and post
144143
regex: /^https:\/\/(?:www\.)?instagram\.com\/(?:reel|p)\/(.*)/,
145144
embedUrl: 'https://www.instagram.com/p/<%= remote_id %>/embed',
146145
html: '<iframe width="400" height="505" style="margin: 0 auto;" frameborder="0" scrolling="no" allowtransparency="true"></iframe>',
@@ -205,6 +204,21 @@ const SERVICES: ServicesConfigType = {
205204
width: 600,
206205
id: (groups) => `${groups.join('/')}.js`,
207206
},
207+
whimsical: {
208+
regex: /(https:\/\/)?whimsical.com\/(?:[a-zA-Z0-9\-]+\-)?([a-km-zA-HJ-NP-Z1-9]{16,22})(@[a-km-zA-HJ-NP-Z1-9]+)?/,
209+
embedUrl: 'https://whimsical.com/embed/<%= remote_id %>',
210+
html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
211+
height: 300,
212+
width: 600,
213+
id: (ids) => ids[1]
214+
},
215+
figma:{
216+
regex: /(https:\/\/www\.figma\.com\/.*)?/,
217+
embedUrl: 'https://www.figma.com/embed?embed_host=share&url=<%= remote_id %>',
218+
html: "<iframe height='450' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
219+
height: 300,
220+
width: 600
221+
},
208222
};
209223

210224
export default SERVICES;

test/services.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,31 @@ describe('Miro service', () => {
612612
expect(embed.data.source).to.be.equal(regularBoardUrl);
613613
});
614614
});
615+
616+
describe('whimsical', () => {
617+
it('should correctly parse URL got from a browser', () => {
618+
const regularBoardUrl = 'https://whimsical.com/test-86ajy7vWEzYATvwFFvbwfA';
619+
const event = composePasteEventMock('pattern', 'whimsical', regularBoardUrl);
620+
621+
embed.onPaste(event);
622+
623+
expect(patterns.whimsical.test(regularBoardUrl)).to.be.true;
624+
expect(embed.data.service).to.be.equal('whimsical');
625+
expect(embed.data.embed).to.be.equal('https://whimsical.com/embed/86ajy7vWEzYATvwFFvbwfA');
626+
expect(embed.data.source).to.be.equal(regularBoardUrl);
627+
});
628+
});
629+
630+
describe('figma', () => {
631+
it('should correctly parse URL got from a browser', () => {
632+
const regularBoardUrl = 'https://www.figma.com/file/3BYrViWFPvfhbrpm1aO3ha/Untitled?type=design&node-id=0%3A1&mode=design&t=WutMRT9L8VJNEL5z-1';
633+
const event = composePasteEventMock('pattern', 'figma', regularBoardUrl);
634+
635+
embed.onPaste(event);
636+
637+
expect(patterns.figma.test(regularBoardUrl)).to.be.true;
638+
expect(embed.data.service).to.be.equal('figma');
639+
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');
640+
expect(embed.data.source).to.be.equal(regularBoardUrl);
641+
});
642+
});

0 commit comments

Comments
 (0)