Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit fb828ab

Browse files
sugarshinngs
authored andcommitted
Update draft-js to v0.10.0 (#18)
1 parent 8d763c3 commit fb828ab

File tree

11 files changed

+34
-34
lines changed

11 files changed

+34
-34
lines changed

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"css-loader": "^0.26.0",
6262
"css-modules-require-hook": "^4.0.5",
6363
"dirty-chai": "^1.2.2",
64-
"draft-js-plugins-editor": "2.0.0-beta7",
64+
"draft-js-plugins-editor": "2.0.0-beta10",
6565
"draft-js-prism": "ngs/draft-js-prism#6edb31c3805dd1de3fb897cc27fced6bac1bafbb",
6666
"enzyme": "^2.6.0",
6767
"eslint": "^3.11.1",
@@ -83,8 +83,10 @@
8383
"nyc": "^10.0.0",
8484
"postcss-loader": "^1.1.1",
8585
"prismjs": "^1.6.0",
86+
"react": "^15.4.1",
8687
"react-addons-pure-render-mixin": "^15.4.1",
8788
"react-addons-test-utils": "^15.4.1",
89+
"react-dom": "^15.4.1",
8890
"react-github-fork-ribbon": "^0.4.4",
8991
"rimraf": "^2.5.4",
9092
"sinon": "^1.17.6",
@@ -97,17 +99,17 @@
9799
"webpack-hot-middleware": "^2.13.2"
98100
},
99101
"peerDependencies": {
100-
"draft-js-plugins-editor": "2.0.0-beta7"
102+
"draft-js-plugins-editor": "2.0.0-beta10",
103+
"react": "^15.0.0",
104+
"react-dom": "^15.0.0"
101105
},
102106
"contributors": [
103107
"Atsushi Nagase <a@ngs.io>"
104108
],
105109
"dependencies": {
106110
"decorate-component-with-props": "^1.0.2",
107-
"draft-js": "^0.9.1",
108-
"draft-js-checkable-list-item": "^2.0.2",
109-
"immutable": "^3.8.1",
110-
"react": "^15.4.1",
111-
"react-dom": "^15.4.1"
111+
"draft-js": "~0.10.0",
112+
"draft-js-checkable-list-item": "^2.0.4",
113+
"immutable": "~3.7.4"
112114
}
113115
}

src/components/Image/__test__/Image-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Entity } from 'draft-js';
2+
import { ContentState } from 'draft-js';
33
import { shallow } from 'enzyme';
44
import chai, { expect } from 'chai';
55
import chaiEnzyme from 'chai-enzyme';
@@ -10,13 +10,14 @@ chai.use(chaiEnzyme());
1010

1111
describe('<Image />', () => {
1212
it('renders anchor tag', () => {
13-
const entityKey = Entity.create('IMG', 'MUTABLE', {
13+
const contentState = ContentState.createFromText('').createEntity('IMG', 'MUTABLE', {
1414
alt: 'alt',
1515
src: 'http://cultofthepartyparrot.com/parrots/aussieparrot.gif',
1616
title: 'parrot'
1717
});
18+
const entityKey = contentState.getLastCreatedEntityKey();
1819
expect(
19-
shallow(<Image entityKey={entityKey}>&nbsp;</Image>).html()
20+
shallow(<Image entityKey={entityKey} contentState={contentState}>&nbsp;</Image>).html()
2021
).to.equal(
2122
'<span> <img src="http://cultofthepartyparrot.com/parrots/aussieparrot.gif" alt="alt" title="parrot"/></span>'
2223
);

src/components/Image/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import { Entity } from 'draft-js';
32

4-
const Image = ({ entityKey, children }) => {
5-
const { src, alt, title } = Entity.get(entityKey).getData();
3+
const Image = ({ entityKey, children, contentState }) => {
4+
const { src, alt, title } = contentState.getEntity(entityKey).getData();
65
return (
76
<span>
87
{children}

src/components/Link/__test__/Link-test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Entity } from 'draft-js';
2+
import { ContentState } from 'draft-js';
33
import { shallow } from 'enzyme';
44
import chai, { expect } from 'chai';
55
import chaiEnzyme from 'chai-enzyme';
@@ -10,12 +10,13 @@ chai.use(chaiEnzyme());
1010

1111
describe('<Link />', () => {
1212
it('renders anchor tag', () => {
13-
const entityKey = Entity.create('LINK', 'MUTABLE', {
13+
const contentState = ContentState.createFromText('').createEntity('LINK', 'MUTABLE', {
1414
href: 'http://cultofthepartyparrot.com/',
1515
title: 'parrot'
1616
});
17+
const entityKey = contentState.getLastCreatedEntityKey();
1718
expect(
18-
shallow(<Link entityKey={entityKey}><b>Hello</b></Link>).html()
19+
shallow(<Link entityKey={entityKey} contentState={contentState}><b>Hello</b></Link>).html()
1920
).to.equal(
2021
'<a href="http://cultofthepartyparrot.com/" title="parrot"><b>Hello</b></a>'
2122
);

src/components/Link/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
import { Entity } from 'draft-js';
32

43
const Link = (props) => {
5-
const { href, title } = Entity.get(props.entityKey).getData();
4+
const { href, title } = props.contentState.getEntity(props.entityKey).getData();
65
return (
76
<a href={href} title={title}>
87
{props.children}

src/decorators/image/__test__/imageStrategy-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('imageStrategy', () => {
4242
const strategy = createImageStrategy();
4343
const cb = sinon.spy();
4444
expect(block).to.be.an('object');
45-
strategy(block, cb);
45+
strategy(block, cb, contentState);
4646
expect(cb).to.have.been.calledWith(0, 1);
4747
});
4848
});

src/decorators/image/imageStrategy.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { Entity } from 'draft-js';
2-
31
const createImageStrategy = () => {
4-
const findImageEntities = (contentBlock, callback) => {
2+
const findImageEntities = (contentBlock, callback, contentState) => {
53
contentBlock.findEntityRanges((character) => {
64
const entityKey = character.getEntity();
75
return (
86
entityKey !== null &&
9-
Entity.get(entityKey).getType() === 'IMG'
7+
contentState.getEntity(entityKey).getType() === 'IMG'
108
);
119
}, callback);
1210
};

src/decorators/link/__test__/linkStrategy-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('linkStrategy', () => {
4141
const strategy = createLinkStrategy();
4242
const cb = sinon.spy();
4343
expect(block).to.be.an('object');
44-
strategy(block, cb);
44+
strategy(block, cb, contentState);
4545
expect(cb).to.have.been.calledWith(7, 12);
4646
});
4747
});

src/decorators/link/linkStrategy.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { Entity } from 'draft-js';
2-
31
const createLinkStrategy = () => {
4-
const findLinkEntities = (contentBlock, callback) => {
2+
const findLinkEntities = (contentBlock, callback, contentState) => {
53
contentBlock.findEntityRanges((character) => {
64
const entityKey = character.getEntity();
75
return (
86
entityKey !== null &&
9-
Entity.get(entityKey).getType() === 'LINK'
7+
contentState.getEntity(entityKey).getType() === 'LINK'
108
);
119
}, callback);
1210
};

src/modifiers/insertImage.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EditorState, RichUtils, SelectionState, Entity, Modifier } from 'draft-js';
1+
import { EditorState, RichUtils, SelectionState, Modifier } from 'draft-js';
22

33
const insertImage = (editorState, matchArr) => {
44
const currentContent = editorState.getCurrentContent();
@@ -16,13 +16,14 @@ const insertImage = (editorState, matchArr) => {
1616
anchorOffset: index,
1717
focusOffset
1818
});
19-
const entityKey = Entity.create(
19+
const nextContent = currentContent.createEntity(
2020
'IMG',
2121
'IMMUTABLE',
2222
{ alt, src, title }
2323
);
24+
const entityKey = nextContent.getLastCreatedEntityKey();
2425
let newContentState = Modifier.replaceText(
25-
currentContent,
26+
nextContent,
2627
wordSelection,
2728
'\u200B',
2829
null,

0 commit comments

Comments
 (0)