|
|
@ -6,6 +6,7 @@ import dynamic from 'next/dynamic'
|
|
|
|
import Dropzone from 'dropperx'
|
|
|
|
import Dropzone from 'dropperx'
|
|
|
|
|
|
|
|
|
|
|
|
// Ours
|
|
|
|
// Ours
|
|
|
|
|
|
|
|
import ApiContext from './ApiContext'
|
|
|
|
import Dropdown from './Dropdown'
|
|
|
|
import Dropdown from './Dropdown'
|
|
|
|
import Settings from './Settings'
|
|
|
|
import Settings from './Settings'
|
|
|
|
import Toolbar from './Toolbar'
|
|
|
|
import Toolbar from './Toolbar'
|
|
|
@ -38,6 +39,7 @@ const BackgroundSelect = dynamic(() => import('./BackgroundSelect'), {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class Editor extends React.Component {
|
|
|
|
class Editor extends React.Component {
|
|
|
|
|
|
|
|
static contextType = ApiContext
|
|
|
|
constructor(props) {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
this.state = {
|
|
|
@ -65,8 +67,8 @@ class Editor extends React.Component {
|
|
|
|
const initialState = Object.keys(queryParams).length ? queryParams : {}
|
|
|
|
const initialState = Object.keys(queryParams).length ? queryParams : {}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// TODO fix this hack
|
|
|
|
// TODO fix this hack
|
|
|
|
if (this.props.api.getGist && path.length >= 19 && path.indexOf('.') === -1) {
|
|
|
|
if (this.context.gist && path.length >= 19 && path.indexOf('.') === -1) {
|
|
|
|
const { content, language } = await this.props.api.getGist(path)
|
|
|
|
const { content, language } = await this.context.gist.get(path)
|
|
|
|
if (language) {
|
|
|
|
if (language) {
|
|
|
|
initialState.language = language.toLowerCase()
|
|
|
|
initialState.language = language.toLowerCase()
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,9 +117,9 @@ class Editor extends React.Component {
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
// if safari, get image from api
|
|
|
|
// if safari, get image from api
|
|
|
|
const isPNG = format !== 'svg'
|
|
|
|
const isPNG = format !== 'svg'
|
|
|
|
if (this.props.api.image && this.isSafari && isPNG) {
|
|
|
|
if (this.context.image && this.isSafari && isPNG) {
|
|
|
|
const encodedState = serializeState(this.state)
|
|
|
|
const encodedState = serializeState(this.state)
|
|
|
|
return this.props.api.image(encodedState)
|
|
|
|
return this.context.image(encodedState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const node = this.carbonNode.current
|
|
|
|
const node = this.carbonNode.current
|
|
|
@ -226,7 +228,7 @@ class Editor extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
upload() {
|
|
|
|
upload() {
|
|
|
|
this.getCarbonImage({ format: 'png' }).then(
|
|
|
|
this.getCarbonImage({ format: 'png' }).then(
|
|
|
|
this.props.api.tweet.bind(null, this.state.code || DEFAULT_CODE)
|
|
|
|
this.context.tweet.bind(null, this.state.code || DEFAULT_CODE)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -322,7 +324,7 @@ class Editor extends React.Component {
|
|
|
|
getCarbonImage={this.getCarbonImage}
|
|
|
|
getCarbonImage={this.getCarbonImage}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<div className="buttons">
|
|
|
|
<div className="buttons">
|
|
|
|
{this.props.api.tweet && <TweetButton onClick={this.upload} />}
|
|
|
|
<TweetButton onClick={this.upload} />
|
|
|
|
<ExportMenu
|
|
|
|
<ExportMenu
|
|
|
|
onChange={this.updateSetting}
|
|
|
|
onChange={this.updateSetting}
|
|
|
|
export={this.export}
|
|
|
|
export={this.export}
|
|
|
@ -385,7 +387,6 @@ function isImage(file) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Editor.defaultProps = {
|
|
|
|
Editor.defaultProps = {
|
|
|
|
api: {},
|
|
|
|
|
|
|
|
onUpdate: () => {},
|
|
|
|
onUpdate: () => {},
|
|
|
|
onReset: () => {}
|
|
|
|
onReset: () => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|