Functional Component Refactor: Figma, Framer, Gist (#4260)
This commit is contained in:
@@ -2,21 +2,21 @@ import * as React from "react";
|
|||||||
import Frame from "../components/Frame";
|
import Frame from "../components/Frame";
|
||||||
import { EmbedProps as Props } from ".";
|
import { EmbedProps as Props } from ".";
|
||||||
|
|
||||||
const URL_REGEX = new RegExp(
|
function Figma(props: Props) {
|
||||||
"https://([w.-]+\\.)?figma\\.com/(file|proto)/([0-9a-zA-Z]{22,128})(?:/.*)?$"
|
return (
|
||||||
);
|
<Frame
|
||||||
|
{...props}
|
||||||
export default class Figma extends React.Component<Props> {
|
src={`https://www.figma.com/embed?embed_host=outline&url=${props.attrs.href}`}
|
||||||
static ENABLED = [URL_REGEX];
|
title="Figma Embed"
|
||||||
|
border
|
||||||
render() {
|
/>
|
||||||
return (
|
);
|
||||||
<Frame
|
|
||||||
{...this.props}
|
|
||||||
src={`https://www.figma.com/embed?embed_host=outline&url=${this.props.attrs.href}`}
|
|
||||||
title="Figma Embed"
|
|
||||||
border
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Figma.ENABLED = [
|
||||||
|
new RegExp(
|
||||||
|
"https://([w.-]+\\.)?figma\\.com/(file|proto)/([0-9a-zA-Z]{22,128})(?:/.*)?$"
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
export default Figma;
|
||||||
|
|||||||
@@ -2,19 +2,12 @@ import * as React from "react";
|
|||||||
import Frame from "../components/Frame";
|
import Frame from "../components/Frame";
|
||||||
import { EmbedProps as Props } from ".";
|
import { EmbedProps as Props } from ".";
|
||||||
|
|
||||||
const URL_REGEX = new RegExp("^https://framer.cloud/(.*)$");
|
function Framer(props: Props) {
|
||||||
|
return (
|
||||||
export default class Framer extends React.Component<Props> {
|
<Frame {...props} src={props.attrs.href} title="Framer Embed" border />
|
||||||
static ENABLED = [URL_REGEX];
|
);
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<Frame
|
|
||||||
{...this.props}
|
|
||||||
src={this.props.attrs.href}
|
|
||||||
title="Framer Embed"
|
|
||||||
border
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Framer.ENABLED = [new RegExp("^https://framer.cloud/(.*)$")];
|
||||||
|
|
||||||
|
export default Framer;
|
||||||
|
|||||||
@@ -2,43 +2,37 @@ import * as React from "react";
|
|||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { EmbedProps as Props } from ".";
|
import { EmbedProps as Props } from ".";
|
||||||
|
|
||||||
const URL_REGEX = new RegExp(
|
|
||||||
"^https://gist\\.github\\.com/([a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38})/(.*)$"
|
|
||||||
);
|
|
||||||
|
|
||||||
class Gist extends React.Component<Props> {
|
|
||||||
static ENABLED = [URL_REGEX];
|
|
||||||
|
|
||||||
get id() {
|
|
||||||
const gistUrl = new URL(this.props.attrs.href);
|
|
||||||
return gistUrl.pathname.split("/")[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const id = this.id;
|
|
||||||
const gistLink = `https://gist.github.com/${id}.js`;
|
|
||||||
const gistScript = `<script type="text/javascript" src="${gistLink}"></script>`;
|
|
||||||
const styles =
|
|
||||||
"<style>*{ font-size:12px; } body { margin: 0; } .gist .blob-wrapper.data { max-height:150px; overflow:auto; }</style>";
|
|
||||||
const iframeHtml = `<html><head><base target="_parent">${styles}</head><body>${gistScript}</body></html>`;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Iframe
|
|
||||||
src={`data:text/html;base64,${btoa(iframeHtml)}`}
|
|
||||||
className={this.props.isSelected ? "ProseMirror-selectednode" : ""}
|
|
||||||
frameBorder="0"
|
|
||||||
width="100%"
|
|
||||||
height="200px"
|
|
||||||
scrolling="no"
|
|
||||||
id={`gist-${id}`}
|
|
||||||
title="Github Gist"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Iframe = styled.iframe`
|
const Iframe = styled.iframe`
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
function Gist(props: Props) {
|
||||||
|
const gistUrl = new URL(props.attrs.href);
|
||||||
|
const id = gistUrl.pathname.split("/")[2];
|
||||||
|
const gistLink = `https://gist.github.com/${id}.js`;
|
||||||
|
const gistScript = `<script type="text/javascript" src="${gistLink}"></script>`;
|
||||||
|
const styles =
|
||||||
|
"<style>*{ font-size:12px; } body { margin: 0; } .gist .blob-wrapper.data { max-height:150px; overflow:auto; }</style>";
|
||||||
|
const iframeHtml = `<html><head><base target="_parent">${styles}</head><body>${gistScript}</body></html>`;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Iframe
|
||||||
|
src={`data:text/html;base64,${btoa(iframeHtml)}`}
|
||||||
|
className={props.isSelected ? "ProseMirror-selectednode" : ""}
|
||||||
|
frameBorder="0"
|
||||||
|
width="100%"
|
||||||
|
height="200px"
|
||||||
|
scrolling="no"
|
||||||
|
id={`gist-${id}`}
|
||||||
|
title="Github Gist"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Gist.ENABLED = [
|
||||||
|
new RegExp(
|
||||||
|
"^https://gist\\.github\\.com/([a-zA-Z\\d](?:[a-zA-Z\\d]|-(?=[a-zA-Z\\d])){0,38})/(.*)$"
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
export default Gist;
|
export default Gist;
|
||||||
|
|||||||
Reference in New Issue
Block a user