|
|
@ -64,15 +64,21 @@ class Editor extends React.Component {
|
|
|
|
const { query, pathname } = url.parse(asPath, true)
|
|
|
|
const { query, pathname } = url.parse(asPath, true)
|
|
|
|
const path = escapeHtml(pathname.split('/').pop())
|
|
|
|
const path = escapeHtml(pathname.split('/').pop())
|
|
|
|
const queryParams = getQueryStringState(query)
|
|
|
|
const queryParams = getQueryStringState(query)
|
|
|
|
const initialState = Object.keys(queryParams).length ? queryParams : {}
|
|
|
|
let initialState = Object.keys(queryParams).length ? queryParams : {}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// TODO fix this hack
|
|
|
|
// TODO fix this hack
|
|
|
|
if (this.context.gist && path.length >= 19 && path.indexOf('.') === -1) {
|
|
|
|
if (path.length >= 19 && path.indexOf('.') === -1 && this.context.gist) {
|
|
|
|
const { content, language } = await this.context.gist.get(path)
|
|
|
|
const { code, language, config } = await await this.context.gist.get(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof config === 'object') {
|
|
|
|
|
|
|
|
initialState = config
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (language) {
|
|
|
|
if (language) {
|
|
|
|
initialState.language = language.toLowerCase()
|
|
|
|
initialState.language = language.toLowerCase()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initialState.code = content
|
|
|
|
|
|
|
|
|
|
|
|
initialState.code = code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
// eslint-disable-next-line
|
|
|
@ -293,68 +299,66 @@ class Editor extends React.Component {
|
|
|
|
const config = omit(this.state, ['code', 'aspectRatio'])
|
|
|
|
const config = omit(this.state, ['code', 'aspectRatio'])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="editor">
|
|
|
|
<div className="editor">
|
|
|
|
<Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
|
|
|
|
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
|
|
|
|
<Dropdown
|
|
|
|
<Dropdown
|
|
|
|
icon={languageIcon}
|
|
|
|
icon={languageIcon}
|
|
|
|
selected={
|
|
|
|
selected={
|
|
|
|
LANGUAGE_NAME_HASH[language] ||
|
|
|
|
LANGUAGE_NAME_HASH[language] ||
|
|
|
|
LANGUAGE_MIME_HASH[language] ||
|
|
|
|
LANGUAGE_MIME_HASH[language] ||
|
|
|
|
LANGUAGE_MODE_HASH[language] ||
|
|
|
|
LANGUAGE_MODE_HASH[language] ||
|
|
|
|
LANGUAGE_MODE_HASH[DEFAULT_LANGUAGE]
|
|
|
|
LANGUAGE_MODE_HASH[DEFAULT_LANGUAGE]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list={LANGUAGES}
|
|
|
|
list={LANGUAGES}
|
|
|
|
onChange={this.updateLanguage}
|
|
|
|
onChange={this.updateLanguage}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<BackgroundSelect
|
|
|
|
<BackgroundSelect
|
|
|
|
onChange={this.updateBackground}
|
|
|
|
onChange={this.updateBackground}
|
|
|
|
mode={backgroundMode}
|
|
|
|
mode={backgroundMode}
|
|
|
|
color={backgroundColor}
|
|
|
|
color={backgroundColor}
|
|
|
|
image={backgroundImage}
|
|
|
|
image={backgroundImage}
|
|
|
|
aspectRatio={aspectRatio}
|
|
|
|
aspectRatio={aspectRatio}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<Settings
|
|
|
|
<Settings
|
|
|
|
{...config}
|
|
|
|
{...config}
|
|
|
|
onChange={this.updateSetting}
|
|
|
|
|
|
|
|
resetDefaultSettings={this.resetDefaultSettings}
|
|
|
|
|
|
|
|
format={this.format}
|
|
|
|
|
|
|
|
applyPreset={this.applyPreset}
|
|
|
|
|
|
|
|
getCarbonImage={this.getCarbonImage}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div className="buttons">
|
|
|
|
|
|
|
|
<TweetButton onClick={this.upload} />
|
|
|
|
|
|
|
|
<ExportMenu
|
|
|
|
onChange={this.updateSetting}
|
|
|
|
onChange={this.updateSetting}
|
|
|
|
resetDefaultSettings={this.resetDefaultSettings}
|
|
|
|
export={this.export}
|
|
|
|
format={this.format}
|
|
|
|
exportSize={exportSize}
|
|
|
|
applyPreset={this.applyPreset}
|
|
|
|
disablePNG={this.disablePNG}
|
|
|
|
getCarbonImage={this.getCarbonImage}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<div className="buttons">
|
|
|
|
</div>
|
|
|
|
<TweetButton onClick={this.upload} />
|
|
|
|
</Toolbar>
|
|
|
|
<ExportMenu
|
|
|
|
|
|
|
|
onChange={this.updateSetting}
|
|
|
|
<Dropzone accept="image/*, text/*, application/*" onDrop={this.onDrop}>
|
|
|
|
export={this.export}
|
|
|
|
{({ canDrop }) => (
|
|
|
|
exportSize={exportSize}
|
|
|
|
<Overlay
|
|
|
|
disablePNG={this.disablePNG}
|
|
|
|
isOver={canDrop}
|
|
|
|
/>
|
|
|
|
title={`Drop your file here to import ${canDrop ? '✋' : '✊'}`}
|
|
|
|
</div>
|
|
|
|
>
|
|
|
|
</Toolbar>
|
|
|
|
{/*key ensures Carbon's internal language state is updated when it's changed by Dropdown*/}
|
|
|
|
|
|
|
|
<Carbon
|
|
|
|
<Dropzone accept="image/*, text/*, application/*" onDrop={this.onDrop}>
|
|
|
|
key={language}
|
|
|
|
{({ canDrop }) => (
|
|
|
|
ref={this.carbonNode}
|
|
|
|
<Overlay
|
|
|
|
config={this.state}
|
|
|
|
isOver={canDrop}
|
|
|
|
onChange={this.updateCode}
|
|
|
|
title={`Drop your file here to import ${canDrop ? '✋' : '✊'}`}
|
|
|
|
onAspectRatioChange={this.updateAspectRatio}
|
|
|
|
|
|
|
|
loading={this.state.loading}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{/*key ensures Carbon's internal language state is updated when it's changed by Dropdown*/}
|
|
|
|
{code != null ? code : DEFAULT_CODE}
|
|
|
|
<Carbon
|
|
|
|
</Carbon>
|
|
|
|
key={language}
|
|
|
|
</Overlay>
|
|
|
|
ref={this.carbonNode}
|
|
|
|
)}
|
|
|
|
config={this.state}
|
|
|
|
</Dropzone>
|
|
|
|
onChange={this.updateCode}
|
|
|
|
|
|
|
|
onAspectRatioChange={this.updateAspectRatio}
|
|
|
|
|
|
|
|
loading={this.state.loading}
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
{code != null ? code : DEFAULT_CODE}
|
|
|
|
|
|
|
|
</Carbon>
|
|
|
|
|
|
|
|
</Overlay>
|
|
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
</Dropzone>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style jsx>
|
|
|
|
<style jsx>
|
|
|
|
{`
|
|
|
|
{`
|
|
|
|
.editor {
|
|
|
|
.editor {
|
|
|
@ -370,7 +374,7 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
`}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|