Skip to content

Commit f033dd1

Browse files
authored
Merge release/v3.0.1 into master
2 parents f2ed81e + 591a05a commit f033dd1

9 files changed

Lines changed: 69 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
CHANGELOG
22
=========
3+
## v3.0.2
4+
* Fix deprecation warnings
5+
* Fix image and video blocks
6+
* Fix onChange not firing when custom blocks are added
7+
38
## v3.0.0
49
* Update for React v15.5 deprecation warnings: PropTypes is now a separate `prop-types` package
510
* Added prettier formatting

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@synapsestudios/draftjs-editor",
3-
"version": "3.0.0",
3+
"version": "3.0.2",
44
"description": "A customized WYSIWYG editor utilizing Facebook's Draft.js library",
55
"repository": {
66
"type": "git",
@@ -57,6 +57,8 @@
5757
"husky": "^0.13.3",
5858
"lint-staged": "^3.4.1",
5959
"prettier": "^1.3.1",
60+
"react": "^15.3.0",
61+
"react-dom": "^15.3.0",
6062
"stylus": "^0.54.5"
6163
},
6264
"peerDependencies": {

src/DraftJSEditor.jsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
CompositeDecorator,
88
Editor,
99
EditorState,
10-
Entity,
1110
RichUtils,
1211
} from 'draft-js';
1312

@@ -62,7 +61,7 @@ class DraftJSEditor extends Component {
6261
this.confirmBlock = this._confirmBlock.bind(this);
6362
this.onBlockInputKeyDown = this._onBlockInputKeyDown.bind(this);
6463
this.onBlockDataChange = this._onBlockDataChange.bind(this);
65-
this.renderBlock = this._renderBlock.bind(this);
64+
this.renderBlock = this._renderBlock.bind(this, editorState.getCurrentContent());
6665
}
6766

6867
componentWillReceiveProps(newProps) {
@@ -140,10 +139,11 @@ class DraftJSEditor extends Component {
140139

141140
_confirmLink() {
142141
const { editorState, urlValue } = this.state;
143-
const entityKey = Entity.create('LINK', 'MUTABLE', {
142+
const contentState = editorState.getCurrentContent().createEntity('LINK', 'MUTABLE', {
144143
target: this.props.linkTarget,
145144
url: urlValue,
146145
});
146+
const entityKey = contentState.getLastCreatedEntityKey();
147147

148148
this.onChange(
149149
RichUtils.toggleLink(editorState, editorState.getSelection(), entityKey)
@@ -186,7 +186,7 @@ class DraftJSEditor extends Component {
186186
this.onChange(RichUtils.toggleLink(editorState, selection, null));
187187
}
188188

189-
_confirmBlock(e, data) {
189+
_confirmBlock(data) {
190190
this.setState(
191191
{
192192
customBlockData: {},
@@ -199,6 +199,8 @@ class DraftJSEditor extends Component {
199199
showCustomBlockInput: false,
200200
},
201201
() => {
202+
const contentState = this.state.editorState.getCurrentContent();
203+
this.props.onChange(convertToRaw(contentState));
202204
setTimeout(() => this.focus(), 0);
203205
}
204206
);
@@ -215,7 +217,8 @@ class DraftJSEditor extends Component {
215217
}
216218

217219
_insertCustomBlock(editorState, type, data) {
218-
const entityKey = Entity.create(type, 'IMMUTABLE', data);
220+
const contentState = editorState.getCurrentContent().createEntity(type, 'IMMUTABLE', data);
221+
const entityKey = contentState.getLastCreatedEntityKey();
219222

220223
// if you use an empty string for the block content here Draft will die
221224
return AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
@@ -240,9 +243,9 @@ class DraftJSEditor extends Component {
240243
}
241244
}
242245

243-
_renderBlock(block) {
246+
_renderBlock(contentState, block) {
244247
if (block.getType() === 'atomic') {
245-
const entityType = Entity.get(block.getEntityAt(0)).getType();
248+
const entityType = contentState.getEntity(block.getEntityAt(0)).getType();
246249

247250
return this.props.customBlocks[entityType]
248251
? this.props.customBlocks[entityType].getBlockRenderer()

src/blocks/img.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Entity } from 'draft-js';
21
import React from 'react';
32
import Photo from '../icons/Photo';
43

54
export default {
65
getBlockRenderer() {
76
return {
87
component: props => {
9-
const entity = Entity.get(props.block.getEntityAt(0)); // eslint-disable-line
8+
const entity = props.contentState.getEntity(props.block.getEntityAt(0)); // eslint-disable-line
109
const { src, alt } = entity.getData();
1110
return <img src={src} alt={alt} />;
1211
},
@@ -62,7 +61,7 @@ export default {
6261
onKeyDown={onKeyDown}
6362
placeholder="Alt text"
6463
/>
65-
<button onMouseDown={onSubmit}>
64+
<button onClick={() => onSubmit(data)}>
6665
Confirm
6766
</button>
6867
</div>

src/blocks/video.jsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ export default {
6464
return transformed;
6565
};
6666

67-
const handleSubmit = e => {
68-
onSubmit(e, {
69-
src: transformSource(data.src),
70-
});
71-
};
72-
7367
return (
7468
<div>
7569
<input
@@ -82,7 +76,9 @@ export default {
8276
this.refs.customBlockInput = c;
8377
}}
8478
/>
85-
<button onMouseDown={handleSubmit}>
79+
<button
80+
onClick={() => onSubmit({ src: transformSource(data.src) })}
81+
>
8682
Confirm
8783
</button>
8884
</div>

src/decorators/link.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { Entity } from 'draft-js';
43

5-
const linkStrategy = (contentBlock, callback) => {
4+
const linkStrategy = (contentBlock, callback, contentState) => {
65
contentBlock.findEntityRanges(character => {
76
const entityKey = character.getEntity();
8-
return entityKey !== null && Entity.get(entityKey).getType() === 'LINK';
7+
return entityKey !== null && contentState.getEntity(entityKey).getType() === 'LINK';
98
}, callback);
109
};
1110

1211
const Link = props => {
13-
const { target, url } = Entity.get(props.entityKey).getData();
12+
const { target, url } = props.contentState.getEntity(props.entityKey).getData();
1413
return (
1514
<a href={url} target={target}>
1615
{props.children}

src/renderer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { convertFromRaw, Entity } from 'draft-js';
1+
import { convertFromRaw } from 'draft-js';
22
import { stateToHTML } from 'draft-js-export-html';
33

44
export default class Renderer {
@@ -9,11 +9,14 @@ export default class Renderer {
99
}
1010

1111
convertRawToHTML(rawContent) {
12+
let entityMapIndex = 0;
1213
const options = {
1314
blockRenderers: {
1415
atomic: block => {
15-
const data = Entity.get(block.getEntityAt(0)).getData();
16-
const type = Entity.get(block.getEntityAt(0)).getType();
16+
const entity = rawContent.entityMap[entityMapIndex];
17+
const data = entity.data;
18+
const type = entity.type;
19+
entityMapIndex += 1;
1720

1821
return this.customBlocks[type]
1922
? this.customBlocks[type].renderHTML(data)

storybook/stories/SetStateExample.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class SetStateExample extends Component {
2222

2323
onChange = content => {
2424
action('onChange')(content); // Log to storybook's "action-logger"
25-
this.setState(content);
25+
this.setState({ content });
2626
};
2727

2828
render() {
2929
return (
3030
<div>
3131
<h1>@synapsestudios/draftjs-editor</h1>
3232
<p className="p text-center">
33-
A customized WYSIWYG editor utilizing Facebook's Draft.js library
33+
{`A customized WYSIWYG editor utilizing Facebook's Draft.js library`}
3434
</p>
3535
<p className="p text-center">
3636
View this project on
@@ -39,7 +39,7 @@ class SetStateExample extends Component {
3939
</p>
4040
<DraftJSEditor
4141
content={this.state.content || null}
42-
onChange={content => this.setState({ content })}
42+
onChange={this.onChange}
4343
placeholder="Tell a story..."
4444
customBlocks={defaultBlocks}
4545
customBlockControls={Object.keys(defaultBlocks)}

yarn.lock

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,14 @@ create-react-class@^15.5.2:
14771477
fbjs "^0.8.9"
14781478
object-assign "^4.1.1"
14791479

1480+
create-react-class@^15.6.0:
1481+
version "15.6.0"
1482+
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.0.tgz#ab448497c26566e1e29413e883207d57cfe7bed4"
1483+
dependencies:
1484+
fbjs "^0.8.9"
1485+
loose-envify "^1.3.1"
1486+
object-assign "^4.1.1"
1487+
14801488
cross-spawn@^5.0.1:
14811489
version "5.1.0"
14821490
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
@@ -3919,6 +3927,13 @@ promise@^7.1.1:
39193927
dependencies:
39203928
asap "~2.0.3"
39213929

3930+
prop-types@^15.5.10:
3931+
version "15.5.10"
3932+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
3933+
dependencies:
3934+
fbjs "^0.8.9"
3935+
loose-envify "^1.3.1"
3936+
39223937
prop-types@^15.5.7, prop-types@^15.5.9:
39233938
version "15.5.9"
39243939
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.9.tgz#d478eef0e761396942f70c78e772f76e8be747c9"
@@ -4008,6 +4023,15 @@ react-docgen@^2.12.1:
40084023
node-dir "^0.1.10"
40094024
recast "^0.11.5"
40104025

4026+
react-dom@^15.3.0:
4027+
version "15.6.1"
4028+
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.1.tgz#2cb0ed4191038e53c209eb3a79a23e2a4cf99470"
4029+
dependencies:
4030+
fbjs "^0.8.9"
4031+
loose-envify "^1.1.0"
4032+
object-assign "^4.1.0"
4033+
prop-types "^15.5.10"
4034+
40114035
react-fuzzy@^0.3.3:
40124036
version "0.3.3"
40134037
resolved "https://registry.yarnpkg.com/react-fuzzy/-/react-fuzzy-0.3.3.tgz#9f6775393cd03bbd3c977651771abe16c8b29a81"
@@ -4066,6 +4090,16 @@ react-stubber@^1.0.0:
40664090
dependencies:
40674091
babel-runtime "^6.5.0"
40684092

4093+
react@^15.3.0:
4094+
version "15.6.1"
4095+
resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df"
4096+
dependencies:
4097+
create-react-class "^15.6.0"
4098+
fbjs "^0.8.9"
4099+
loose-envify "^1.1.0"
4100+
object-assign "^4.1.0"
4101+
prop-types "^15.5.10"
4102+
40694103
"readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.1.4, readable-stream@^2.2.2, readable-stream@^2.2.6:
40704104
version "2.2.9"
40714105
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8"

0 commit comments

Comments
 (0)