Skip to content

Commit 9cee3cf

Browse files
committed
Fix issue of block data undefined breaking code.
1 parent 102fa91 commit 9cee3cf

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

dist/html-to-draftjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/html-to-draftjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "html-to-draftjs",
3-
"version": "0.1.0-beta2",
3+
"version": "0.1.0-beta3",
44
"main": "dist/html-to-draftjs.js",
55
"repository": {
66
"type": "git",

src/index.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@ import htmlToDraft from './library';
77
import '../node_modules/react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
88
import './styles.css';
99

10+
// in constructor, I use your code above, but I change outputEditorState to inputEditorState
11+
// in the first Editor, I use this.state.inputEditorState as editorState
12+
1013
class Playground extends Component {
1114

12-
state = {
13-
outputEditorState: undefined,
15+
// state = {
16+
// outputEditorState: undefined,
17+
// }
18+
19+
constructor(props) {
20+
super(props)
21+
const html = '<p>123</p>'
22+
const contentBlock = htmlToDraft(html);
23+
if (contentBlock) {
24+
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);
25+
const inputEditorState = EditorState.createWithContent(contentState);
26+
this.state = {
27+
inputEditorState,
28+
};
29+
}
1430
}
1531

1632
onInputEditorChange = (inputEditorState) => {
33+
console.log('*****', inputEditorState.getCurrentContent())
1734
const rawContent = convertToRaw(inputEditorState.getCurrentContent());
1835
const html = draftToHtml(rawContent);
1936
const contentBlock = htmlToDraft(html);
@@ -32,10 +49,13 @@ class Playground extends Component {
3249
}
3350

3451
render() {
52+
// console.log('*****', this.state.inputEditorState.getCurrentContent())
53+
// value={this.state.inputEditorState && draftToHtml(convertToRaw(this.state.inputEditorState.getCurrentContent()))}
3554
return (
3655
<div>
3756
<div style={{ height: 200 }}>
3857
<Editor
58+
editorState={this.state.inputEditorState}
3959
onEditorStateChange={this.onInputEditorChange}
4060
mention={{
4161
separator: ' ',
@@ -56,26 +76,10 @@ class Playground extends Component {
5676
<textarea
5777
disabled
5878
className="demo-content"
59-
value={this.state.inputEditorState && draftToHtml(convertToRaw(this.state.inputEditorState.getCurrentContent()))}
6079
/>
6180
</div>
6281
<div style={{ height: 200 }}>
63-
<Editor
64-
editorState={this.state.outputEditorState}
65-
mention={{
66-
separator: ' ',
67-
trigger: '@',
68-
suggestions: [
69-
{ text: 'A', value: 'a', url: 'href-a' },
70-
{ text: 'AB', value: 'ab', url: 'href-ab' },
71-
{ text: 'ABC', value: 'abc', url: 'href-abc' },
72-
{ text: 'ABCD', value: 'abcd', url: 'href-abcd' },
73-
{ text: 'ABCDE', value: 'abcde', url: 'href-abcde' },
74-
{ text: 'ABCDEF', value: 'abcdef', url: 'href-abcdef' },
75-
{ text: 'ABCDEFG', value: 'abcdefg', url: 'href-abcdefg' },
76-
],
77-
}}
78-
/>
82+
7983
</div>
8084
</div>
8185
);

src/library/chunkBuilder.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OrderedSet } from 'immutable';
1+
import { OrderedSet, Map } from 'immutable';
22

33
const SPACE = ' ';
44
const MAX_DEPTH = 4;
@@ -46,29 +46,27 @@ const getEmptyChunk = (): Object => {
4646
};
4747

4848
const getFirstBlockChunk = (blockType: string, data: Object): Object => {
49-
console.log('data 1', data)
5049
return {
5150
text: '',
5251
inlines: [],
5352
entities: [],
5453
blocks: [{
5554
type: blockType,
5655
depth: 0,
57-
data,
56+
data: data || new Map({}),
5857
}],
5958
};
6059
};
6160

6261
const getBlockDividerChunk = (blockType: string, depth: number, data: Object): Object => {
63-
console.log('data 2', data)
6462
return {
6563
text: '\r',
6664
inlines: [],
6765
entities: [],
6866
blocks: [{
6967
type: blockType,
7068
depth: Math.max(0, Math.min(MAX_DEPTH, depth)),
71-
data,
69+
data: data || new Map({}),
7270
}],
7371
};
7472
};
@@ -81,6 +79,7 @@ const getAtomicBlockChunk = (entityId: number): Object => {
8179
blocks: [{
8280
type: 'atomic',
8381
depth: 0,
82+
data: {}
8483
}],
8584
};
8685
};

src/library/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ function genFragment(
6363
entityConfig.src = node.src;
6464
entityConfig.height = node.height;
6565
entityConfig.width = node.width;
66-
console.log('entityConfig', entityConfig)
6766
const entityId = Entity.create(
6867
'EMBEDDED_LINK',
6968
'MUTABLE',

0 commit comments

Comments
 (0)