Skip to content

Commit d39c680

Browse files
committed
move plugin props into an object
1 parent e565a3b commit d39c680

File tree

5 files changed

+47
-38
lines changed

5 files changed

+47
-38
lines changed

src/hashtagPlugin/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import Hashtag from './Hashtag';
22
import hashtagStrategy from './hashtagStrategy';
33

44
const hashtagPlugin = (config) => ({
5-
// standard plugin property
6-
decorators: [
7-
{
8-
strategy: hashtagStrategy,
9-
component: (config !== undefined && config.Hashtag !== undefined ? config.Hashtag : Hashtag),
10-
},
11-
],
5+
pluginProps: {
6+
decorators: [
7+
{
8+
strategy: hashtagStrategy,
9+
component: (config !== undefined && config.Hashtag !== undefined ? config.Hashtag : Hashtag),
10+
},
11+
],
12+
},
1213
Hashtag,
1314
});
1415

src/linkifyPlugin/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import Link from './Link';
22
import linkStrategy from './linkStrategy';
33

44
const linkPlugin = (config) => ({
5-
// standard plugin property
6-
decorators: [
7-
{
8-
strategy: linkStrategy,
9-
component: (config !== undefined && config.Link !== undefined ? config.Link : Link),
10-
},
11-
],
5+
pluginProps: {
6+
decorators: [
7+
{
8+
strategy: linkStrategy,
9+
component: (config !== undefined && config.Link !== undefined ? config.Link : Link),
10+
},
11+
],
12+
},
1213
Link,
1314
});
1415

src/mentionPlugin/index.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,28 @@ const ariaProps = {
2323
};
2424

2525
const metionsPlugin = (config) => ({
26-
// standard plugin property
27-
decorators: [
28-
{
29-
strategy: mentionStrategy,
30-
component: Mention,
26+
pluginProps: {
27+
decorators: [
28+
{
29+
strategy: mentionStrategy,
30+
component: Mention,
31+
},
32+
{
33+
strategy: mentionSearchStrategy,
34+
component: MentionSearch(config.mentions, callbacks, ariaProps),
35+
},
36+
],
37+
getEditorProps: () => ariaProps,
38+
keyBindingFn: (keyboardEvent) => callbacks.keyBindingFn && callbacks.keyBindingFn(keyboardEvent),
39+
handleKeyCommand: (command) => callbacks.handleKeyCommand && callbacks.handleKeyCommand(command),
40+
onDownArrow: (keyboardEvent) => callbacks.onDownArrow && callbacks.onDownArrow(keyboardEvent),
41+
onUpArrow: (keyboardEvent) => callbacks.onUpArrow && callbacks.onUpArrow(keyboardEvent),
42+
onEscape: (keyboardEvent) => callbacks.onEscape && callbacks.onEscape(keyboardEvent),
43+
handleReturn: (keyboardEvent) => callbacks.handleReturn && callbacks.handleReturn(keyboardEvent),
44+
onChange: (editorState) => {
45+
if (callbacks.onChange) return callbacks.onChange(editorState);
46+
return editorState;
3147
},
32-
{
33-
strategy: mentionSearchStrategy,
34-
component: MentionSearch(config.mentions, callbacks, ariaProps),
35-
},
36-
],
37-
getEditorProps: () => ariaProps,
38-
keyBindingFn: (keyboardEvent) => callbacks.keyBindingFn && callbacks.keyBindingFn(keyboardEvent), // standard plugin callback
39-
handleKeyCommand: (command) => callbacks.handleKeyCommand && callbacks.handleKeyCommand(command), // standard plugin callback
40-
onDownArrow: (keyboardEvent) => callbacks.onDownArrow && callbacks.onDownArrow(keyboardEvent), // standard plugin callback
41-
onUpArrow: (keyboardEvent) => callbacks.onUpArrow && callbacks.onUpArrow(keyboardEvent), // standard plugin callback
42-
onEscape: (keyboardEvent) => callbacks.onEscape && callbacks.onEscape(keyboardEvent), // standard plugin callback
43-
handleReturn: (keyboardEvent) => callbacks.handleReturn && callbacks.handleReturn(keyboardEvent), // standard plugin callback
44-
onChange: (editorState) => {
45-
if (callbacks.onChange) return callbacks.onChange(editorState);
46-
return editorState;
4748
},
4849
});
4950

src/pluginEditor/Editor/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ import {
1212
import createCompositeDecorator from '../utils/createCompositeDecorator';
1313
import moveToEndOfSelectedBlock from '../modifiers/moveToEndOfSelectedBlock';
1414
import moveToStartOfSelectedBlock from '../modifiers/moveToStartOfSelectedBlock';
15+
import { List } from 'immutable';
1516

1617
export default class PluginEditor extends Component {
1718

1819
// TODO add flow types & propTypes - since it's a library and people might not use flow we want to have both
1920

2021
constructor(props) {
2122
super(props);
22-
this.plugins = props.plugins;
23-
const compositeDecorator = createCompositeDecorator(this.props.plugins, this);
23+
this.plugins = List(props.plugins)
24+
.filter((plugin) => plugin.pluginProps !== undefined)
25+
.map((plugin) => plugin.pluginProps)
26+
.toArray();
27+
const compositeDecorator = createCompositeDecorator(this.plugins, this);
2428

2529
// TODO consider triggering an onChange here to make sure the editorState is in sync
2630
// with the outer Editor context

src/stickerPlugin/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import sticker from './Sticker';
66
import stickerSelect from './StickerSelect';
77

88
const stickerPlugin = (config) => ({
9+
pluginProps: {
10+
blockRendererFn: blockRendererFn(config),
11+
onChange: cleanupEmptyStickers,
12+
},
913
add: addSticker,
10-
blockRendererFn: blockRendererFn(config), // standard plugin callback
11-
onChange: cleanupEmptyStickers, // standard plugin callback
1214
remove: removeSticker,
1315
Sticker: sticker(config.stickers, config.hasRemove),
1416
StickerSelect: stickerSelect(config.stickers),

0 commit comments

Comments
 (0)