|
|
@ -96,6 +96,8 @@ class Editor extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
carbonNode = React.createRef()
|
|
|
|
carbonNode = React.createRef()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getTheme = () => this.props.themes.find(t => t.id === this.state.theme) || DEFAULT_THEME
|
|
|
|
|
|
|
|
|
|
|
|
updateState = updates => {
|
|
|
|
updateState = updates => {
|
|
|
|
this.setState(updates, () => {
|
|
|
|
this.setState(updates, () => {
|
|
|
|
if (!this.gist) {
|
|
|
|
if (!this.gist) {
|
|
|
@ -117,7 +119,10 @@ 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.context.image && this.isSafari && isPNG) {
|
|
|
|
if (this.context.image && this.isSafari && isPNG) {
|
|
|
|
const encodedState = serializeState(this.state)
|
|
|
|
const themeConfig = this.getTheme()
|
|
|
|
|
|
|
|
const highlights = { ...themeConfig.highlights, ...this.state.highlights }
|
|
|
|
|
|
|
|
// TODO: pull from state highlights, or custom theme highlights, or
|
|
|
|
|
|
|
|
const encodedState = serializeState({ ...this.state, highlights })
|
|
|
|
return this.context.image(encodedState)
|
|
|
|
return this.context.image(encodedState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -261,6 +266,13 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateTheme = theme => this.updateState({ theme })
|
|
|
|
updateTheme = theme => this.updateState({ theme })
|
|
|
|
|
|
|
|
updateHighlights = updates =>
|
|
|
|
|
|
|
|
this.setState(({ highlights = {} }) => ({
|
|
|
|
|
|
|
|
highlights: {
|
|
|
|
|
|
|
|
...highlights,
|
|
|
|
|
|
|
|
...updates
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
createTheme = theme => {
|
|
|
|
createTheme = theme => {
|
|
|
|
this.props.updateThemes(themes => [theme, ...themes])
|
|
|
|
this.props.updateThemes(themes => [theme, ...themes])
|
|
|
@ -284,6 +296,7 @@ class Editor extends React.Component {
|
|
|
|
render() {
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
theme,
|
|
|
|
theme,
|
|
|
|
|
|
|
|
highlights,
|
|
|
|
language,
|
|
|
|
language,
|
|
|
|
backgroundColor,
|
|
|
|
backgroundColor,
|
|
|
|
backgroundImage,
|
|
|
|
backgroundImage,
|
|
|
@ -294,16 +307,19 @@ class Editor extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
const config = omit(this.state, ['code'])
|
|
|
|
const config = omit(this.state, ['code'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const themeConfig = this.getTheme()
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="editor">
|
|
|
|
<div className="editor">
|
|
|
|
<Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Themes
|
|
|
|
<Themes
|
|
|
|
|
|
|
|
theme={theme}
|
|
|
|
|
|
|
|
highlights={highlights}
|
|
|
|
update={this.updateTheme}
|
|
|
|
update={this.updateTheme}
|
|
|
|
|
|
|
|
updateHighlights={this.updateHighlights}
|
|
|
|
remove={this.removeTheme}
|
|
|
|
remove={this.removeTheme}
|
|
|
|
create={this.createTheme}
|
|
|
|
create={this.createTheme}
|
|
|
|
theme={theme}
|
|
|
|
|
|
|
|
themes={this.props.themes}
|
|
|
|
themes={this.props.themes}
|
|
|
|
router={this.props.router}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
<Dropdown
|
|
|
|
<Dropdown
|
|
|
|
icon={languageIcon}
|
|
|
|
icon={languageIcon}
|
|
|
@ -353,6 +369,7 @@ class Editor extends React.Component {
|
|
|
|
key={language}
|
|
|
|
key={language}
|
|
|
|
ref={this.carbonNode}
|
|
|
|
ref={this.carbonNode}
|
|
|
|
config={this.state}
|
|
|
|
config={this.state}
|
|
|
|
|
|
|
|
theme={themeConfig}
|
|
|
|
onChange={this.updateCode}
|
|
|
|
onChange={this.updateCode}
|
|
|
|
loading={this.state.loading}
|
|
|
|
loading={this.state.loading}
|
|
|
|
>
|
|
|
|
>
|
|
|
|