Skip to content

Commit e9e118f

Browse files
committed
adding support for mention tag
1 parent ceb39db commit e9e118f

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

src/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,22 @@ class Playground extends Component {
5858
/>
5959
</div>
6060
<div style={{ height: 200 }}>
61-
<Editor editorState={this.state.outputEditorState} />
61+
<Editor
62+
editorState={this.state.outputEditorState}
63+
mention={{
64+
separator: ' ',
65+
trigger: '@',
66+
suggestions: [
67+
{ text: 'A', value: 'a', url: 'href-a' },
68+
{ text: 'AB', value: 'ab', url: 'href-ab' },
69+
{ text: 'ABC', value: 'abc', url: 'href-abc' },
70+
{ text: 'ABCD', value: 'abcd', url: 'href-abcd' },
71+
{ text: 'ABCDE', value: 'abcde', url: 'href-abcde' },
72+
{ text: 'ABCDEF', value: 'abcdef', url: 'href-abcdef' },
73+
{ text: 'ABCDEFG', value: 'abcdefg', url: 'href-abcdefg' },
74+
],
75+
}}
76+
/>
6277
</div>
6378
</div>
6479
);

src/library/getBlockTypeForTag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const blockRenderMap = new Map({
3434
element: 'figure',
3535
},
3636
unstyled: {
37-
element: 'div',
37+
element: 'p',
3838
},
3939
});
4040

src/library/getEntityId.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ const getEntityId = (node) => {
66
node instanceof HTMLAnchorElement
77
) {
88
const entityConfig = {};
9-
entityConfig.url = node.href;
10-
entityConfig.title = node.innerHTML;
11-
entityId = Entity.create(
12-
'LINK',
13-
'MUTABLE',
14-
entityConfig,
15-
);
9+
if (node.dataset.mention !== undefined) {
10+
entityConfig.url = node.href;
11+
entityConfig.text = node.innerHTML;
12+
entityConfig.value = node.dataset.value;
13+
entityId = Entity.create(
14+
'MENTION',
15+
'IMMUTABLE',
16+
entityConfig,
17+
);
18+
} else {
19+
entityConfig.url = node.href;
20+
entityConfig.title = node.innerHTML;
21+
entityId = Entity.create(
22+
'LINK',
23+
'MUTABLE',
24+
entityConfig,
25+
);
26+
}
1627
}
1728
return entityId;
1829
}

0 commit comments

Comments
 (0)