From dc1bc44c8f71df4d05e1f44ecc426fab037531e1 Mon Sep 17 00:00:00 2001 From: milesstoetzner Date: Tue, 26 Jan 2021 05:47:23 +0100 Subject: [PATCH] feat: Google Drawings Integration (#1814) * add google drawings integration * add google drawings image * update google drawings image and regex * allow query parameter in google drawings regex * support CDN for google drawings image --- app/embeds/GoogleDrawings.js | 39 ++++++++++++++++++++++++++++++ app/embeds/GoogleDrawings.test.js | 29 ++++++++++++++++++++++ app/embeds/index.js | 8 ++++++ public/images/google-drawings.png | Bin 0 -> 1447 bytes 4 files changed, 76 insertions(+) create mode 100644 app/embeds/GoogleDrawings.js create mode 100644 app/embeds/GoogleDrawings.test.js create mode 100644 public/images/google-drawings.png diff --git a/app/embeds/GoogleDrawings.js b/app/embeds/GoogleDrawings.js new file mode 100644 index 000000000..6be5db510 --- /dev/null +++ b/app/embeds/GoogleDrawings.js @@ -0,0 +1,39 @@ +// @flow +import * as React from "react"; +import Image from "components/Image"; +import Frame from "./components/Frame"; + +const URL_REGEX = new RegExp( + "^https://docs.google.com/drawings/d/(.*)/(edit|preview)(.*)$" +); + +type Props = {| + attrs: {| + href: string, + matches: string[], + |}, +|}; + +export default class GoogleDrawings extends React.Component { + static ENABLED = [URL_REGEX]; + + render() { + return ( + + } + canonicalUrl={this.props.attrs.href.replace("/preview", "/edit")} + title="Google Drawings" + border + /> + ); + } +} diff --git a/app/embeds/GoogleDrawings.test.js b/app/embeds/GoogleDrawings.test.js new file mode 100644 index 000000000..27617ed8c --- /dev/null +++ b/app/embeds/GoogleDrawings.test.js @@ -0,0 +1,29 @@ +/* eslint-disable flowtype/require-valid-file-annotation */ +import GoogleDrawings from "./GoogleDrawings"; + +describe("GoogleDrawings", () => { + const match = GoogleDrawings.ENABLED[0]; + test("to be enabled on share link", () => { + expect( + "https://docs.google.com/drawings/d/1zDLtJ4HSCnjGCGSoCgqGe3F8p6o7R8Vjk8MDR6dKf-U/edit".match( + match + ) + ).toBeTruthy(); + expect( + "https://docs.google.com/drawings/d/1zDLtJ4HSCnjGCGSoCgqGe3F8p6o7R8Vjk8MDR6dKf-U/edit?usp=sharing".match( + match + ) + ).toBeTruthy(); + }); + + test("to not be enabled elsewhere", () => { + expect( + "https://docs.google.com/drawings/d/e/2PACX-1vRtzIzEWN6svSrIYZq-kq2XZEN6WaOFXHbPKRLXNOFRlxLIdJg0Vo6RfretGqs9SzD-fUazLeS594Kw/pub?w=960&h=720".match( + match + ) + ).toBe(null); + expect("https://docs.google.com/drawings".match(match)).toBe(null); + expect("https://docs.google.com".match(match)).toBe(null); + expect("https://www.google.com".match(match)).toBe(null); + }); +}); diff --git a/app/embeds/index.js b/app/embeds/index.js index 0e1c07e6f..1e389a53f 100644 --- a/app/embeds/index.js +++ b/app/embeds/index.js @@ -10,6 +10,7 @@ import Figma from "./Figma"; import Framer from "./Framer"; import Gist from "./Gist"; import GoogleDocs from "./GoogleDocs"; +import GoogleDrawings from "./GoogleDrawings"; import GoogleDrive from "./GoogleDrive"; import GoogleSheets from "./GoogleSheets"; import GoogleSlides from "./GoogleSlides"; @@ -95,6 +96,13 @@ export default [ component: Gist, matcher: matcher(Gist), }, + { + title: "Google Drawings", + keywords: "drawings", + icon: () => , + component: GoogleDrawings, + matcher: matcher(GoogleDrawings), + }, { title: "Google Drive", keywords: "drive", diff --git a/public/images/google-drawings.png b/public/images/google-drawings.png new file mode 100644 index 0000000000000000000000000000000000000000..d690ddff904062d3cffa919d35a9e22a89a8d79a GIT binary patch literal 1447 zcmZuxYd8}M7~Wy7BU>cbLp(*fbq*CrC)8ZVNiFyLNDPr|nHj@6ZmGyM#xxqq5R?1m zEM_ie?i~!db0VXx^aQP#@Y%Fibke4kVQkzJ^~v>s7E7aj9&yR zJL-cq6@;Y^0YO59SbqAev3d5KX+=;Wl9?gZ{QU0Om$!c1-=MTEAw8GX)==1497?uY zY(;?9UxZsDYmM)eRMLt$tuDI@<~jQu8P?I3BAR*fNme0i9Ur`kq6sD%g&8q~FmNuL zIFgr0`JlkUqf>m6708UKUVWWFEl0J-40qlr4Gjy3Pu?<4Qao6L9NB0Q<==Y!bxg$8)1;6YLQF<9J6yBrS=XV7&vkAHGF>#N>HUd}+7Yuk@mhT%hC)zvnNW1KlWZ;@`nr2=3ZKyw348c*4IkAYje%pTVT??Cd25s?A8V%+ zRar;O-{ssHHT3L2{I3Jg23DBt=xNQIihX&oLT=l3!derY?iqErzxCtqT%n`E97B1> z&H87no9=Ppf6y`io0zXZ{Vqt~$;|rew3XQFUZYU#2YE`p-(&WeOXYGRJ&tg~`I``a za|_arZ3Y8vyy*2WvIvL}O&LhTLaGR`Fgw${OER}}F$tmw+=}zwEQ_I;FG#$mQ`t)w;c?B z<{9 literal 0 HcmV?d00001