|
|
@ -1,12 +1,10 @@
|
|
|
|
// Theirs
|
|
|
|
// Theirs
|
|
|
|
import url from 'url'
|
|
|
|
import url from 'url'
|
|
|
|
import React from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
import HTML5Backend from 'react-dnd-html5-backend'
|
|
|
|
|
|
|
|
import { DragDropContext } from 'react-dnd'
|
|
|
|
|
|
|
|
import domtoimage from 'dom-to-image'
|
|
|
|
import domtoimage from 'dom-to-image'
|
|
|
|
import ReadFileDropContainer, { DATA_URL, TEXT } from 'dropperx'
|
|
|
|
|
|
|
|
import Spinner from 'react-spinner'
|
|
|
|
import Spinner from 'react-spinner'
|
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
import dynamic from 'next/dynamic'
|
|
|
|
|
|
|
|
import Dropzone from 'react-dropzone'
|
|
|
|
|
|
|
|
|
|
|
|
// Ours
|
|
|
|
// Ours
|
|
|
|
import Button from './Button'
|
|
|
|
import Button from './Button'
|
|
|
@ -245,6 +243,14 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onDrop([file]) {
|
|
|
|
onDrop([file]) {
|
|
|
|
|
|
|
|
if (!file) return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO abstract this into Dropperx
|
|
|
|
|
|
|
|
reader.onload = event => {
|
|
|
|
|
|
|
|
file.content = event.target.result
|
|
|
|
|
|
|
|
|
|
|
|
if (isImage(file)) {
|
|
|
|
if (isImage(file)) {
|
|
|
|
this.updateState({
|
|
|
|
this.updateState({
|
|
|
|
backgroundImage: file.content,
|
|
|
|
backgroundImage: file.content,
|
|
|
@ -257,6 +263,13 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isImage(file)) {
|
|
|
|
|
|
|
|
reader.readAsDataURL(file)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
reader.readAsText(file, 'UTF-8')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateTheme(theme) {
|
|
|
|
updateTheme(theme) {
|
|
|
|
this.updateSetting('theme', theme)
|
|
|
|
this.updateSetting('theme', theme)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -325,7 +338,11 @@ class Editor extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<React.Fragment>
|
|
|
|
<div className="editor">
|
|
|
|
<Dropzone accept="image/*, text/*, application/*" onDrop={this.onDrop}>
|
|
|
|
|
|
|
|
{({ getRootProps, isDragAccept }) => {
|
|
|
|
|
|
|
|
const root = getRootProps()
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div className="editor" {...root}>
|
|
|
|
<Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
|
|
|
|
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
|
|
|
|
<Dropdown
|
|
|
|
<Dropdown
|
|
|
@ -376,11 +393,9 @@ class Editor extends React.Component {
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Toolbar>
|
|
|
|
</Toolbar>
|
|
|
|
|
|
|
|
|
|
|
|
<ReadFileDropContainer readAs={readAs} onDrop={this.onDrop}>
|
|
|
|
|
|
|
|
{({ isOver, canDrop }) => (
|
|
|
|
|
|
|
|
<Overlay
|
|
|
|
<Overlay
|
|
|
|
isOver={isOver || canDrop}
|
|
|
|
isOver={isDragAccept}
|
|
|
|
title={`Drop your file here to import ${isOver ? '✋' : '✊'}`}
|
|
|
|
title={`Drop your file here to import ${isDragAccept ? '✋' : '✊'}`}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
{/*key ensures Carbon's internal language state is updated when it's changed by Dropdown*/}
|
|
|
|
{/*key ensures Carbon's internal language state is updated when it's changed by Dropdown*/}
|
|
|
|
<Carbon
|
|
|
|
<Carbon
|
|
|
@ -395,12 +410,14 @@ class Editor extends React.Component {
|
|
|
|
{code != null ? code : DEFAULT_CODE}
|
|
|
|
{code != null ? code : DEFAULT_CODE}
|
|
|
|
</Carbon>
|
|
|
|
</Carbon>
|
|
|
|
</Overlay>
|
|
|
|
</Overlay>
|
|
|
|
)}
|
|
|
|
|
|
|
|
</ReadFileDropContainer>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
</Dropzone>
|
|
|
|
<style jsx>
|
|
|
|
<style jsx>
|
|
|
|
{`
|
|
|
|
{`
|
|
|
|
.editor {
|
|
|
|
.editor {
|
|
|
|
|
|
|
|
outline: none;
|
|
|
|
background: ${COLORS.BLACK};
|
|
|
|
background: ${COLORS.BLACK};
|
|
|
|
border: 3px solid ${COLORS.SECONDARY};
|
|
|
|
border: 3px solid ${COLORS.SECONDARY};
|
|
|
|
border-radius: 8px;
|
|
|
|
border-radius: 8px;
|
|
|
@ -429,17 +446,10 @@ function isImage(file) {
|
|
|
|
return file.type.split('/')[0] === 'image'
|
|
|
|
return file.type.split('/')[0] === 'image'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function readAs(file) {
|
|
|
|
|
|
|
|
if (isImage(file)) {
|
|
|
|
|
|
|
|
return DATA_URL
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return TEXT
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Editor.defaultProps = {
|
|
|
|
Editor.defaultProps = {
|
|
|
|
api: {},
|
|
|
|
api: {},
|
|
|
|
onUpdate: () => {},
|
|
|
|
onUpdate: () => {},
|
|
|
|
onReset: () => {}
|
|
|
|
onReset: () => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default DragDropContext(HTML5Backend)(Editor)
|
|
|
|
export default Editor
|
|
|
|