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

Commit a494c28

Browse files
committed
boing
1 parent 9348a05 commit a494c28

File tree

5 files changed

+131
-20
lines changed

5 files changed

+131
-20
lines changed

demo/client/components/DemoEditor/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ export default class DemoEditor extends Component {
4545
};
4646

4747
focus = () => {
48+
console.log("damnit");
4849
this.editor.focus();
4950
};
5051

5152
render() {
5253
const { editorState } = this.state;
5354
return (
5455
<div className={styles.root}>
55-
<div className={styles.editor}>
56+
<div className={styles.editor} onClick={this.focus}>
5657
<Editor
5758
editorState={editorState}
5859
onChange={this.onChange}

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"flow-bin": "^0.36.0",
6666
"history": "^2.0.0",
6767
"husky": "^0.14.3",
68+
"jest": "^21.1.0",
6869
"jsdom": "^9.8.3",
6970
"lint-staged": "^4.2.1",
7071
"mocha": "^3.2.0",
@@ -81,30 +82,33 @@
8182
"react-dom": "^15.4.1",
8283
"react-github-corner": "^2.0.0",
8384
"react-github-fork-ribbon": "^0.4.4",
85+
"react-test-renderer": "^16.2.0",
8486
"rimraf": "^2.5.4",
8587
"sinon": "^1.17.6",
8688
"static-site-generator-webpack-plugin": "^3.1.0",
8789
"style-loader": "^0.13.1",
8890
"url-loader": "^0.5.7",
8991
"webpack": "^1.13.3",
9092
"webpack-dev-middleware": "^1.8.4",
91-
"webpack-hot-middleware": "^2.13.2",
92-
"jest": "^21.1.0",
93-
"react-test-renderer": "^16.2.0"
93+
"webpack-hot-middleware": "^2.13.2"
9494
},
9595
"peerDependencies": {
9696
"draft-js-plugins-editor": "~2.0.0-rc.1 || 2.0.0-rc2 || 2.0.0-rc1 || 2.0.0-beta12",
9797
"react": "^15.0.0",
98-
"react-dom": "^15.0.0"
98+
"react-dom": "^15.0.0",
99+
"react-modal": "3.x",
100+
"react-portal": "^4.1.4"
99101
},
100102
"contributors": [
101103
"Atsushi Nagase <a@ngs.io>"
102104
],
103105
"dependencies": {
104106
"decorate-component-with-props": "^1.0.2",
105-
"draft-js": "~0.10.1",
107+
"draft-js": "^0.10.4",
106108
"draft-js-checkable-list-item": "^2.0.5",
107109
"draft-js-prism-plugin": "^0.1.1",
108-
"immutable": "~3.7.4"
110+
"immutable": "~3.7.4",
111+
"react-modal": "^3.3.2",
112+
"react-popover": "^0.4.0"
109113
}
110114
}

src/components/Code/index.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { PureComponent } from "react";
22
import { Map } from "immutable";
33
import { EditorState, EditorBlock, Modifier } from "draft-js";
4+
import Modal from "react-modal";
45

56
const languages = {
67
bash: "Bash",
@@ -22,11 +23,22 @@ const languages = {
2223
swift: "Swift",
2324
};
2425

26+
const hidden = {};
27+
2528
class CodeBlock extends PureComponent {
29+
state = {
30+
isOpen: false,
31+
};
32+
2633
onChange = ev => {
2734
ev.preventDefault();
35+
ev.stopPropagation();
2836
const blockKey = this.props.block.getKey();
29-
const { getEditorState, setEditorState } = this.props.blockProps;
37+
const {
38+
getEditorState,
39+
setEditorState,
40+
getEditorRef,
41+
} = this.props.blockProps;
3042
const editorState = getEditorState();
3143
const selection = editorState.getSelection();
3244
const language = ev.currentTarget.value;
@@ -40,12 +52,19 @@ class CodeBlock extends PureComponent {
4052
"change-block-data"
4153
);
4254

43-
// setTimeout(() => {
44-
// setEditorState(EditorState.forceSelection(
45-
// newEditorState,
46-
// content.getSelectionAfter()
47-
// ))
48-
// }, 3000)
55+
setTimeout(() => {
56+
setEditorState(
57+
EditorState.forceSelection(newEditorState, content.getSelectionAfter())
58+
);
59+
}, 2);
60+
};
61+
62+
cancelClicks = event => event.preventDefault();
63+
64+
preventBubbling = event => event.stopPropagation();
65+
66+
wat = () => {
67+
console.log("yo wtf");
4968
};
5069

5170
render() {
@@ -54,8 +73,13 @@ class CodeBlock extends PureComponent {
5473
return (
5574
<div>
5675
<EditorBlock {...this.props} />
57-
<div contentEditable={false}>
58-
<select value={language} onChange={this.onChange}>
76+
<div>
77+
<select
78+
contentEditable={false}
79+
onClick={this.preventBubbling}
80+
value={language}
81+
onChange={this.onChange}
82+
>
5983
{Object.keys(this.props.languages).map(lang => (
6084
<option key={lang} value={lang}>
6185
{this.props.languages[lang]}

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const createMarkdownPlugin = (config = {}) => {
126126
return null;
127127
},
128128

129-
blockRendererFn(block, { setEditorState, getEditorState }) {
129+
blockRendererFn(block, { setEditorState, getEditorState, getEditorRef }) {
130130
switch (block.getType()) {
131131
case CHECKABLE_LIST_ITEM: {
132132
return {
@@ -144,6 +144,7 @@ const createMarkdownPlugin = (config = {}) => {
144144
return {
145145
component: CodeBlock,
146146
props: {
147+
getEditorRef,
147148
setEditorState,
148149
language: block.getData().get("language"),
149150
getEditorState,

yarn.lock

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,14 @@ create-error-class@^3.0.0:
15461546
dependencies:
15471547
capture-stack-trace "^1.0.0"
15481548

1549+
create-react-class@^15.5.3:
1550+
version "15.6.3"
1551+
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
1552+
dependencies:
1553+
fbjs "^0.8.9"
1554+
loose-envify "^1.3.1"
1555+
object-assign "^4.1.1"
1556+
15491557
create-react-class@^15.6.0:
15501558
version "15.6.0"
15511559
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.0.tgz#ab448497c26566e1e29413e883207d57cfe7bed4"
@@ -1653,6 +1661,12 @@ css-selector-tokenizer@^0.7.0:
16531661
fastparse "^1.1.1"
16541662
regexpu-core "^1.0.0"
16551663

1664+
css-vendor@^0.3.1:
1665+
version "0.3.8"
1666+
resolved "https://registry.yarnpkg.com/css-vendor/-/css-vendor-0.3.8.tgz#6421cfd3034ce664fe7673972fd0119fc28941fa"
1667+
dependencies:
1668+
is-in-browser "^1.0.2"
1669+
16561670
css-what@2.1:
16571671
version "2.1.0"
16581672
resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.0.tgz#9467d032c38cfaefb9f2d79501253062f87fa1bd"
@@ -1922,7 +1936,15 @@ draft-js-prism@ngs/draft-js-prism#6edb31c3805dd1de3fb897cc27fced6bac1bafbb:
19221936
immutable "*"
19231937
prismjs "^1.5.0"
19241938

1925-
draft-js@~0.10.0, draft-js@~0.10.1:
1939+
draft-js@^0.10.4:
1940+
version "0.10.5"
1941+
resolved "https://registry.yarnpkg.com/draft-js/-/draft-js-0.10.5.tgz#bfa9beb018fe0533dbb08d6675c371a6b08fa742"
1942+
dependencies:
1943+
fbjs "^0.8.15"
1944+
immutable "~3.7.4"
1945+
object-assign "^4.1.0"
1946+
1947+
draft-js@~0.10.0:
19261948
version "0.10.2"
19271949
resolved "https://registry.yarnpkg.com/draft-js/-/draft-js-0.10.2.tgz#b722613cb306cfee910f9de1789f2cc3023772e7"
19281950
dependencies:
@@ -2323,6 +2345,10 @@ execa@^0.8.0:
23232345
signal-exit "^3.0.0"
23242346
strip-eof "^1.0.0"
23252347

2348+
exenv@^1.2.0:
2349+
version "1.2.2"
2350+
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
2351+
23262352
exit-hook@^1.0.0:
23272353
version "1.1.1"
23282354
resolved "https://registry.yarnpkg.com/exit-hook/-/exit-hook-1.1.1.tgz#f05ca233b48c05d54fff07765df8507e95c02ff8"
@@ -2435,7 +2461,7 @@ fbjs@^0.8.12:
24352461
setimmediate "^1.0.5"
24362462
ua-parser-js "^0.7.9"
24372463

2438-
fbjs@^0.8.16, fbjs@^0.8.4, fbjs@^0.8.9:
2464+
fbjs@^0.8.15, fbjs@^0.8.16, fbjs@^0.8.4, fbjs@^0.8.9:
24392465
version "0.8.16"
24402466
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.16.tgz#5e67432f550dc41b572bf55847b8aca64e5337db"
24412467
dependencies:
@@ -3174,6 +3200,10 @@ is-glob@^4.0.0:
31743200
dependencies:
31753201
is-extglob "^2.1.1"
31763202

3203+
is-in-browser@^1.0.2:
3204+
version "1.1.3"
3205+
resolved "https://registry.yarnpkg.com/is-in-browser/-/is-in-browser-1.1.3.tgz#56ff4db683a078c6082eb95dad7dc62e1d04f835"
3206+
31773207
is-my-json-valid@^2.10.0, is-my-json-valid@^2.12.4:
31783208
version "2.16.1"
31793209
resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.1.tgz#5a846777e2c2620d1e69104e5d3a03b1f6088f11"
@@ -3949,6 +3979,12 @@ lodash.create@3.1.1:
39493979
lodash._basecreate "^3.0.0"
39503980
lodash._isiterateecall "^3.0.0"
39513981

3982+
lodash.debounce@^3.0.0:
3983+
version "3.1.1"
3984+
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-3.1.1.tgz#812211c378a94cc29d5aa4e3346cf0bfce3a7df5"
3985+
dependencies:
3986+
lodash._getnative "^3.0.0"
3987+
39523988
lodash.defaults@^3.1.2:
39533989
version "3.1.2"
39543990
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-3.1.2.tgz#c7308b18dbf8bc9372d701a73493c61192bd2e2c"
@@ -4020,6 +4056,12 @@ lodash.some@^4.4.0:
40204056
version "4.6.0"
40214057
resolved "https://registry.yarnpkg.com/lodash.some/-/lodash.some-4.6.0.tgz#1bb9f314ef6b8baded13b549169b2a945eb68e4d"
40224058

4059+
lodash.throttle@^3.0.3:
4060+
version "3.0.4"
4061+
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-3.0.4.tgz#bc4f471fb328e4d6fdc6df2b3d3caf113f0f89c9"
4062+
dependencies:
4063+
lodash.debounce "^3.0.0"
4064+
40234065
lodash.uniq@^4.5.0:
40244066
version "4.5.0"
40254067
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
@@ -5255,6 +5297,10 @@ react-deep-force-update@^1.0.0:
52555297
version "1.1.1"
52565298
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-1.1.1.tgz#bcd31478027b64b3339f108921ab520b4313dc2c"
52575299

5300+
react-dom-factories@^1.0.0:
5301+
version "1.0.2"
5302+
resolved "https://registry.yarnpkg.com/react-dom-factories/-/react-dom-factories-1.0.2.tgz#eb7705c4db36fb501b3aa38ff759616aa0ff96e0"
5303+
52585304
react-dom@^15.4.1:
52595305
version "15.6.1"
52605306
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.1.tgz#2cb0ed4191038e53c209eb3a79a23e2a4cf99470"
@@ -5272,6 +5318,25 @@ react-github-fork-ribbon@^0.4.4:
52725318
version "0.4.5"
52735319
resolved "https://registry.yarnpkg.com/react-github-fork-ribbon/-/react-github-fork-ribbon-0.4.5.tgz#2d3586bfde368a19aef7b4a46471e0839c9bc010"
52745320

5321+
react-modal@^3.3.2:
5322+
version "3.3.2"
5323+
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.3.2.tgz#b13da9490653a7c76bc0e9600323eb1079c620e7"
5324+
dependencies:
5325+
exenv "^1.2.0"
5326+
prop-types "^15.5.10"
5327+
warning "^3.0.0"
5328+
5329+
react-popover@^0.4.0:
5330+
version "0.4.18"
5331+
resolved "https://registry.yarnpkg.com/react-popover/-/react-popover-0.4.18.tgz#c8a5aacdddf5a883068368ea1f589dfd3bdd4943"
5332+
dependencies:
5333+
create-react-class "^15.5.3"
5334+
css-vendor "^0.3.1"
5335+
debug "^2.6.8"
5336+
lodash.throttle "^3.0.3"
5337+
prop-types "^15.5.10"
5338+
react-dom-factories "^1.0.0"
5339+
52755340
react-proxy@^1.1.7:
52765341
version "1.1.8"
52775342
resolved "https://registry.yarnpkg.com/react-proxy/-/react-proxy-1.1.8.tgz#9dbfd9d927528c3aa9f444e4558c37830ab8c26a"
@@ -5298,7 +5363,7 @@ react-transform-hmr@^1.0.3:
52985363
global "^4.3.0"
52995364
react-proxy "^1.1.7"
53005365

5301-
react@*, react@^15.4.1:
5366+
react@*:
53025367
version "15.6.1"
53035368
resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df"
53045369
dependencies:
@@ -5308,6 +5373,16 @@ react@*, react@^15.4.1:
53085373
object-assign "^4.1.0"
53095374
prop-types "^15.5.10"
53105375

5376+
react@^15.4.1:
5377+
version "15.6.2"
5378+
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
5379+
dependencies:
5380+
create-react-class "^15.6.0"
5381+
fbjs "^0.8.9"
5382+
loose-envify "^1.1.0"
5383+
object-assign "^4.1.0"
5384+
prop-types "^15.5.10"
5385+
53115386
read-pkg-up@^1.0.1:
53125387
version "1.0.1"
53135388
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02"
@@ -6400,6 +6475,12 @@ warning@^2.0.0:
64006475
dependencies:
64016476
loose-envify "^1.0.0"
64026477

6478+
warning@^3.0.0:
6479+
version "3.0.0"
6480+
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
6481+
dependencies:
6482+
loose-envify "^1.0.0"
6483+
64036484
watch@~0.10.0:
64046485
version "0.10.0"
64056486
resolved "https://registry.yarnpkg.com/watch/-/watch-0.10.0.tgz#77798b2da0f9910d595f1ace5b0c2258521f21dc"

0 commit comments

Comments
 (0)