Skip to content

Commit 666e618

Browse files
authored
Merge branch 'master' into header-return-fix
2 parents 20dd6f2 + 655c2d3 commit 666e618

File tree

13 files changed

+6734
-62
lines changed

13 files changed

+6734
-62
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ lib
4040
demo/public
4141
.deploy
4242
test-results.xml
43-
44-
yarn.lock

.mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
--compilers js:babel-core/register
22
--recursive
3+
--require raf/polyfill
34
--require testHelper.js
45
--reporter mocha-multi-reporters --reporter-options configFile=.mocha-multi-reporters.json

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8.9.4

circle.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
machine:
22
timezone: UTC
33
node:
4-
version: 4.2.6
4+
version: 8.9.4
55
pre:
66
- "git config --global user.name 'Circle CI'"
77
- "git config --global user.email '[email protected]'"
88
general:
99
branches:
1010
ignore:
1111
- gh-pages
12+
dependencies:
13+
override:
14+
- yarn
15+
cache_directories:
16+
- ~/.cache/yarn
1217
test:
1318
override:
1419
- npm test

package.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "draft-js-markdown-shortcuts-plugin",
3-
"version": "0.3.0",
3+
"version": "0.4.1",
44
"description": "A DraftJS plugin for supporting Markdown syntax shortcuts",
55
"main": "lib/index.js",
66
"scripts": {
@@ -55,15 +55,16 @@
5555
"babel-preset-react-hmre": "^1.1.1",
5656
"babel-preset-stage-0": "^6.16.0",
5757
"chai": "^3.5.0",
58-
"chai-enzyme": "^0.6.1",
58+
"chai-enzyme": "^1.0.0-beta.0",
5959
"cheerio": "^0.22.0",
6060
"coveralls": "^2.11.15",
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-rc2",
65-
"draft-js-prism": "ngs/draft-js-prism#6edb31c3805dd1de3fb897cc27fced6bac1bafbb",
66-
"enzyme": "^2.6.0",
64+
"draft-js-plugins-editor": "2.0.4",
65+
"draft-js-prism": "^1.0.5",
66+
"enzyme": "^3.3.0",
67+
"enzyme-adapter-react-16": "^1.1.1",
6768
"eslint": "^3.11.1",
6869
"eslint-config-airbnb": "^13.0.0",
6970
"eslint-plugin-import": "^2.2.0",
@@ -83,11 +84,12 @@
8384
"nyc": "^10.0.0",
8485
"postcss-loader": "^1.1.1",
8586
"prismjs": "^1.6.0",
86-
"react": "^15.4.1",
87+
"raf": "^3.4.0",
88+
"react": "^16.2.0",
8789
"react-addons-pure-render-mixin": "^15.4.1",
8890
"react-addons-test-utils": "^15.4.1",
89-
"react-dom": "^15.4.1",
90-
"react-github-fork-ribbon": "^0.4.4",
91+
"react-dom": "^16.2.0",
92+
"react-github-fork-ribbon": "^0.5.1",
9193
"rimraf": "^2.5.4",
9294
"sinon": "^1.17.6",
9395
"sinon-chai": "^2.8.0",
@@ -99,17 +101,17 @@
99101
"webpack-hot-middleware": "^2.13.2"
100102
},
101103
"peerDependencies": {
102-
"draft-js-plugins-editor": "~2.0.0-rc.1 || 2.0.0-rc2 || 2.0.0-rc1 || 2.0.0-beta12",
103-
"react": "^15.0.0",
104-
"react-dom": "^15.0.0"
104+
"draft-js-plugins-editor": "^2.0.0 || ~2.0.0-rc.1 || 2.0.0-rc2 || 2.0.0-rc1 || 2.0.0-beta12",
105+
"react": "^16.0.0 || ^15.0.0",
106+
"react-dom": "^16.0.0 || ^15.0.0"
105107
},
106108
"contributors": [
107109
"Atsushi Nagase <[email protected]>"
108110
],
109111
"dependencies": {
110-
"decorate-component-with-props": "^1.0.2",
111-
"draft-js": "~0.10.1",
112-
"draft-js-checkable-list-item": "^2.0.5",
112+
"decorate-component-with-props": "^1.1.0",
113+
"draft-js": "~0.10.5",
114+
"draft-js-checkable-list-item": "^3.0.1",
113115
"immutable": "~3.7.4"
114116
}
115117
}

src/__test__/plugin-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ describe('draft-js-markdown-shortcuts-plugin', () => {
349349
});
350350
[
351351
'replaceText',
352-
'insertEmptyBlock',
353352
'handleBlockType',
354353
'handleImage',
355354
'handleLink',

src/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ import createLinkDecorator from './decorators/link';
1919
import createImageDecorator from './decorators/image';
2020
import { replaceText } from './utils';
2121

22-
const INLINE_STYLE_CHARACTERS = [' ', '*', '_'];
23-
2422
function checkCharacterForState(editorState, character) {
2523
let newEditorState = handleBlockType(editorState, character);
24+
const contentState = editorState.getCurrentContent();
25+
const selection = editorState.getSelection();
26+
const key = selection.getStartKey();
27+
const currentBlock = contentState.getBlockForKey(key);
28+
const type = currentBlock.getType();
2629
if (editorState === newEditorState) {
2730
newEditorState = handleImage(editorState, character);
2831
}
2932
if (editorState === newEditorState) {
3033
newEditorState = handleLink(editorState, character);
3134
}
32-
if (editorState === newEditorState) {
35+
if (editorState === newEditorState && type !== 'code-block') {
3336
newEditorState = handleInlineStyle(editorState, character);
3437
}
3538
return newEditorState;
@@ -62,7 +65,9 @@ function checkReturnForState(editorState, ev) {
6265
newEditorState = insertText(editorState, '\n');
6366
}
6467
}
65-
68+
if (editorState === newEditorState) {
69+
newEditorState = handleInlineStyle(editorState, '\n');
70+
}
6671
return newEditorState;
6772
}
6873

@@ -129,7 +134,7 @@ const createMarkdownShortcutsPlugin = (config = {}) => {
129134
return 'not-handled';
130135
},
131136
handleBeforeInput(character, editorState, { setEditorState }) {
132-
if (character !== ' ') {
137+
if (character.match(/[A-z0-9_*~`]/)) {
133138
return 'not-handled';
134139
}
135140
const newEditorState = checkCharacterForState(editorState, character);
@@ -146,7 +151,7 @@ const createMarkdownShortcutsPlugin = (config = {}) => {
146151
let newEditorState = editorState;
147152
let buffer = [];
148153
for (let i = 0; i < text.length; i++) { // eslint-disable-line no-plusplus
149-
if (INLINE_STYLE_CHARACTERS.indexOf(text[i]) >= 0) {
154+
if (text[i].match(/[^A-z0-9_*~`]/)) {
150155
newEditorState = replaceText(newEditorState, buffer.join('') + text[i]);
151156
newEditorState = checkCharacterForState(newEditorState, text[i]);
152157
buffer = [];

src/modifiers/__test__/changeCurrentInlineStyle-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('changeCurrentInlineStyle', () => {
3232
it('changes block type', () => {
3333
const text = 'foo `bar` baz';
3434
const editorState = createEditorState(text, []);
35-
const matchArr = ['`bar`', 'bar'];
35+
const matchArr = ['`bar` ', '`', 'bar', '`', ' '];
3636
matchArr.index = 4;
3737
matchArr.input = text;
3838
const newEditorState = changeCurrentInlineStyle(
@@ -41,7 +41,7 @@ describe('changeCurrentInlineStyle', () => {
4141
expect(
4242
Draft.convertToRaw(newEditorState.getCurrentContent())
4343
).to.deep.equal(
44-
rawContentState('foo bar baz', [{
44+
rawContentState('foo bar baz', [{
4545
length: 3,
4646
offset: 4,
4747
style: 'CODE'

src/modifiers/__test__/handleInlineStyle-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('handleInlineStyle', () => {
5858
entityMap: {},
5959
blocks: [{
6060
key: 'item1',
61-
text: 'hello inline style',
61+
text: 'hello inline style',
6262
type: 'unstyled',
6363
depth: 0,
6464
inlineStyleRanges: [{
@@ -96,7 +96,7 @@ describe('handleInlineStyle', () => {
9696
entityMap: {},
9797
blocks: [{
9898
key: 'item1',
99-
text: 'hello inline style',
99+
text: 'hello inline style',
100100
type: 'unstyled',
101101
depth: 0,
102102
inlineStyleRanges: [{
@@ -134,7 +134,7 @@ describe('handleInlineStyle', () => {
134134
entityMap: {},
135135
blocks: [{
136136
key: 'item1',
137-
text: 'hello inline style',
137+
text: 'hello inline style',
138138
type: 'unstyled',
139139
depth: 0,
140140
inlineStyleRanges: [{
@@ -172,7 +172,7 @@ describe('handleInlineStyle', () => {
172172
entityMap: {},
173173
blocks: [{
174174
key: 'item1',
175-
text: 'hello inline style',
175+
text: 'hello inline style',
176176
type: 'unstyled',
177177
depth: 0,
178178
inlineStyleRanges: [{
@@ -214,7 +214,7 @@ describe('handleInlineStyle', () => {
214214
entityMap: {},
215215
blocks: [{
216216
key: 'item1',
217-
text: 'hello inline style',
217+
text: 'hello inline style',
218218
type: 'unstyled',
219219
depth: 0,
220220
inlineStyleRanges: [{
@@ -256,7 +256,7 @@ describe('handleInlineStyle', () => {
256256
entityMap: {},
257257
blocks: [{
258258
key: 'item1',
259-
text: 'hello inline style',
259+
text: 'hello inline style',
260260
type: 'unstyled',
261261
depth: 0,
262262
inlineStyleRanges: [{
@@ -294,7 +294,7 @@ describe('handleInlineStyle', () => {
294294
entityMap: {},
295295
blocks: [{
296296
key: 'item1',
297-
text: 'hello inline style',
297+
text: 'hello inline style',
298298
type: 'unstyled',
299299
depth: 0,
300300
inlineStyleRanges: [{
@@ -339,7 +339,7 @@ describe('handleInlineStyle', () => {
339339
entityMap: {},
340340
blocks: [{
341341
key: 'item1',
342-
text: 'hello inline style',
342+
text: 'hello inline style',
343343
type: 'unstyled',
344344
depth: 0,
345345
inlineStyleRanges: [{
@@ -386,7 +386,7 @@ describe('handleInlineStyle', () => {
386386
entityMap: {},
387387
blocks: [{
388388
key: 'item1',
389-
text: 'hello inline style',
389+
text: 'hello inline style',
390390
type: 'unstyled',
391391
depth: 0,
392392
inlineStyleRanges: [{

src/modifiers/changeCurrentInlineStyle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ const changeCurrentInlineStyle = (editorState, matchArr, style) => {
1111
const newStyle = currentInlineStyle.merge([style]);
1212
const focusOffset = index + matchArr[0].length;
1313
const wordSelection = SelectionState.createEmpty(key).merge({
14-
anchorOffset: index,
14+
anchorOffset: index + matchArr[0].indexOf(matchArr[1]),
1515
focusOffset
1616
});
1717
let newContentState = Modifier.replaceText(
1818
currentContent,
1919
wordSelection,
20-
matchArr[1],
20+
matchArr[2],
2121
newStyle
2222
);
2323
newContentState = Modifier.insertText(
2424
newContentState,
2525
newContentState.getSelectionAfter(),
26-
' '
26+
matchArr[4]
2727
);
2828
const newEditorState = EditorState.push(
2929
editorState,

0 commit comments

Comments
 (0)