Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.

Commit 8b86481

Browse files
committed
- fixed utils, EditorContainer, atomic block plugin
1 parent 6f7b84e commit 8b86481

File tree

7 files changed

+66
-49
lines changed

7 files changed

+66
-49
lines changed

packages/atomic-block/rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import pkg from './package.json'
99

1010
export default {
1111
external: [
12-
'draft-js/lib/DraftOffsetKey',
1312
'@djsp/core',
1413
'@djsp/utils',
1514
'draft-js',
15+
'draft-js/lib/DraftOffsetKey',
16+
'react',
1617
],
1718
input: 'src/index.js',
1819
output: [

packages/atomic-block/src/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AtomicBlockPlugin extends Component<Props, State> {
5555
constructor(props) {
5656
super(props)
5757

58-
const { registerPlugin } = this.props
58+
const { registerPlugin } = props
5959

6060
this.unregister = registerPlugin({
6161
blockRendererFn: this.blockRendererFn,
@@ -171,8 +171,18 @@ class AtomicBlockPlugin extends Component<Props, State> {
171171

172172
handleReturn = (event, editorState) => {
173173
const { setEditorState } = this.props
174+
const selection = editorState.getSelection()
175+
176+
const currentBlock = editorState
177+
.getCurrentContent()
178+
.getBlockForKey(selection.getStartKey())
179+
180+
if (selection.isCollapsed() && currentBlock.getType() === 'atomic') {
181+
setEditorState(insertNewLine(editorState))
182+
return constants.HANDLED
183+
}
174184

175-
setEditorState(insertNewLine(editorState))
185+
return constants.NOT_HANDLED
176186
}
177187

178188
blockRendererFn = block => {

packages/core/src/EditorContainer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export const withPluginContext = <Props: {}>(
4343
function WithConsumer(props: Object) {
4444
return (
4545
<Context.Consumer>
46-
{contextProps => <Comp {...props} {...contextProps.pluginProps} />}
46+
{contextProps => {
47+
return <Comp {...props} {...contextProps.pluginProps} />
48+
}}
4749
</Context.Consumer>
4850
)
4951
}

packages/utils/package-lock.json

Lines changed: 41 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utils/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
"access": "public"
2323
},
2424
"devDependencies": {
25-
"@djsp/core": "^0.1.3",
25+
"@babel/preset-flow": "^7.0.0",
2626
"cross-env": "^5.1.4",
2727
"flow-bin": "^0.81.0",
2828
"flow-typed": "^2.5.1",
2929
"react": "^16.2.0",
30+
"react-dom": "^16.6.0",
3031
"rollup": "^0.66.2",
3132
"rollup-plugin-babel": "^4.0.3",
3233
"rollup-plugin-commonjs": "^9.1.8",
@@ -39,6 +40,6 @@
3940
"draft-js": "^0.10.5"
4041
},
4142
"dependencies": {
42-
"@babel/preset-flow": "^7.0.0"
43+
"draft-js": "^0.10.5"
4344
}
4445
}

packages/utils/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
format: 'es',
1717
},
1818
],
19-
external: ['draft-js'],
19+
external: ['draft-js', 'immutable'],
2020
plugins: [
2121
external(),
2222
babel({

packages/utils/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,13 @@ export function hasEntity(
202202
const insertBlockAfterSelection = (contentState, selectionState, newBlock) => {
203203
const targetKey = selectionState.getStartKey()
204204
const array = []
205+
205206
contentState.getBlockMap().forEach((block, blockKey) => {
206207
array.push(block)
207208
if (blockKey !== targetKey) return
208209
array.push(newBlock)
209210
})
211+
210212
return contentState.merge({
211213
blockMap: BlockMapBuilder.createFromArray(array),
212214
selectionBefore: selectionState,
@@ -223,12 +225,14 @@ const insertBlockAfterSelection = (contentState, selectionState, newBlock) => {
223225
export function insertNewLine(editorState: EditorState) {
224226
const contentState = editorState.getCurrentContent()
225227
const selectionState = editorState.getSelection()
228+
226229
const newLineBlock = new ContentBlock({
227230
key: generateRandomKey(),
228231
type: 'unstyled',
229232
text: '',
230233
characterList: List(),
231234
})
235+
232236
const withNewLine = insertBlockAfterSelection(
233237
contentState,
234238
selectionState,

0 commit comments

Comments
 (0)