Skip to content

Commit a14b4f3

Browse files
committed
Merge pull request draft-js-plugins#159 from draft-js-plugins/remove-injectBlockProps
Remove inject block props
2 parents 6b80665 + 2d76cd6 commit a14b4f3

File tree

4 files changed

+14
-39
lines changed

4 files changed

+14
-39
lines changed

draft-js-dnd-plugin/src/blockRendererFn.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Entity } from 'draft-js';
22
import removeBlock from './modifiers/removeBlock';
3+
import refreshEditorState from './modifiers/refreshEditorState';
34

45
export default (config) => (contentBlock, getEditorState, updateEditorState) => {
56
const type = contentBlock.getType();
@@ -11,6 +12,9 @@ export default (config) => (contentBlock, getEditorState, updateEditorState) =>
1112
props: {
1213
...data,
1314
remove: () => updateEditorState(removeBlock(getEditorState(), contentBlock.key)),
15+
16+
// This is for block-alignment-wrapper, only temporarily living here
17+
refreshEditorState: () => updateEditorState(refreshEditorState(getEditorState())),
1418
},
1519
};
1620
}

draft-js-dnd-plugin/src/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const uploadPlugin = (config = {}) => {
3131
...config,
3232
emitter,
3333
Image: decorateComponentWithProps(config.Image || Image, { theme, attachButtons }),
34+
35+
// This is for block-alignment-wrapper, only temporarily living here
36+
refreshEditorState: (editorState, onChange) => onChange(EditorState.forceSelection(editorState, editorState.getCurrentContent().getSelectionAfter())),
3437
};
3538

3639
return {
@@ -39,14 +42,6 @@ const uploadPlugin = (config = {}) => {
3942
blockRendererFn: blockRendererFn(blockRendererConfig),
4043
handleDroppedFiles: onDropFile(blockRendererConfig),
4144
handleDrop: onDropBlock(blockRendererConfig),
42-
43-
// This is for block-alignment-wrapper, only temporarily living here
44-
injectBlockProps: (block, getEditorState, onChange) => {
45-
const editorState = getEditorState();
46-
return {
47-
refreshEditorState: () => onChange(EditorState.forceSelection(editorState, editorState.getCurrentContent().getSelectionAfter())),
48-
};
49-
},
5045
},
5146
addListener: emitter.addListener,
5247
removeListener: emitter.removeListener,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { EditorState } from 'draft-js';
2+
3+
export default function (editorState) {
4+
return EditorState.forceSelection(editorState, editorState.getCurrentContent().getSelectionAfter());
5+
}

draft-js-plugins-editor/src/Editor/index.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -191,41 +191,12 @@ export default class PluginEditor extends Component {
191191
return command !== undefined ? command : getDefaultKeyBinding(keyboardEvent);
192192
};
193193

194-
// Inject props into blockRendererFn blocks
195-
injectBlockProps(b) {
196-
let props = {};
197-
const block = b;
198-
199-
if (this.props.injectBlockProps) {
200-
const result = this.props.injectBlockProps(block, this.getEditorState, this.onChange);
201-
if (result) {
202-
props = { ...result, ...props };
203-
}
204-
}
205-
206-
this.plugins
207-
.forEach((plugin) => {
208-
if (plugin.injectBlockProps) {
209-
const result = plugin.injectBlockProps(block, this.getEditorState, this.onChange);
210-
if (result) {
211-
props = { ...result, ...props };
212-
}
213-
}
214-
215-
return undefined;
216-
});
217-
218-
if (block.props) block.props = { ...block.props, ...props };
219-
else block.props = props;
220-
return block;
221-
}
222-
223194
blockRendererFn = (contentBlock) => {
224195
// TODO optimize to break after the first one
225196
if (this.props.blockRendererFn) {
226197
const result = this.props.blockRendererFn(contentBlock);
227198
if (result) {
228-
return this.injectBlockProps(result);
199+
return result;
229200
}
230201
}
231202

@@ -234,7 +205,7 @@ export default class PluginEditor extends Component {
234205
if (plugin.blockRendererFn) {
235206
const result = plugin.blockRendererFn(contentBlock, this.getEditorState, this.onChange);
236207
if (result) {
237-
return this.injectBlockProps(result);
208+
return result;
238209
}
239210
}
240211

0 commit comments

Comments
 (0)