This repository was archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
66 lines (61 loc) · 1.37 KB
/
App.js
File metadata and controls
66 lines (61 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { Component } from 'react'
import { EditorState, convertFromRaw } from 'draft-js'
import { EditorContainer, Editor } from '@djsp/core'
import AtomicBlock from '@djsp/atomic-block'
import './styles.css'
const rawContent = {
blocks: [
{
text: 'Hey there duder',
},
{
type: 'atomic',
text: ' ',
entityRanges: [
{
key: 0,
length: 1,
offset: 0,
},
],
},
],
entityMap: {
0: {
data: {
title: 'Kitten',
src: 'https://placekitten.com/200/200',
},
mutability: 'IMMUTABLE',
type: 'IMAGE',
},
},
}
export default class App extends Component {
state = {
editorState: EditorState.createWithContent(convertFromRaw(rawContent)),
}
onChange = editorState => this.setState({ editorState })
render() {
return (
<div>
<EditorContainer
editorState={this.state.editorState}
onChange={this.onChange}>
<Editor />
<AtomicBlock type="image">
{({ isFocused, blockProps: { src, title } }) => {
return (
<img
className={isFocused ? 'focused' : ''}
src={src}
alt={title}
/>
)
}}
</AtomicBlock>
</EditorContainer>
</div>
)
}
}