-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathintro.js
85 lines (77 loc) · 2.45 KB
/
intro.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from 'react';
import ReactDOM from 'react-dom';
import DraftailEditor, { ENTITY_TYPE, BLOCK_TYPE, INLINE_STYLE } from '../lib';
import LinkSource from './sources/LinkSource';
import ImageSource from './sources/ImageSource';
import EmbedSource from './sources/EmbedSource';
import Link from './entities/Link';
import introContentState from './utils/introContentState';
const mount = document.querySelector('[data-mount-intro]');
const onSave = contentState => {
sessionStorage.setItem('intro:contentState', JSON.stringify(contentState));
};
const editor = (
<DraftailEditor
rawContentState={introContentState}
onSave={onSave}
placeholder="Write here…"
enableHorizontalRule={true}
enableLineBreak={true}
showUndoRedoControls={true}
stripPastedStyles={false}
entityTypes={[
{
type: ENTITY_TYPE.LINK,
description: 'Link',
icon: 'icon-link',
source: LinkSource,
decorator: Link,
},
{
type: ENTITY_TYPE.IMAGE,
description: 'Image',
icon: 'icon-image',
source: ImageSource,
imageFormats: [],
},
{
type: ENTITY_TYPE.EMBED,
description: 'Embed',
icon: 'icon-media',
source: EmbedSource,
},
]}
blockTypes={[
{
type: BLOCK_TYPE.HEADER_TWO,
label: 'H2',
description: 'Heading 2',
},
{
type: BLOCK_TYPE.HEADER_THREE,
label: 'H3',
description: 'Heading 3',
},
{ label: 'Code', type: BLOCK_TYPE.CODE, icon: 'icon-cog' },
{
type: BLOCK_TYPE.UNORDERED_LIST_ITEM,
description: 'Bulleted list',
icon: 'icon-list-ul',
},
]}
inlineStyles={[
{ type: INLINE_STYLE.BOLD, description: 'Bold', icon: 'icon-bold' },
{
type: INLINE_STYLE.ITALIC,
description: 'Italic',
icon: 'icon-italic',
},
{
type: INLINE_STYLE.KEYBOARD,
description: 'Keyboard shortcut',
label: '⌘',
},
]}
/>
);
ReactDOM.render(editor, mount);