Skip to content

Commit b7f158c

Browse files
Farzad HayatMitchC1999
andauthored
DOC-2174: added documentation for Mentions plugin's getUsers API deprecation to 6.0-release-notes-premium-changes.adoc and migration-from-5x.adoc (#3060)
* added getusers-api-alternative demo to 6.0 release notes and the 5 to 6 migration guide * fix demo toolbar * added changelog entry * Apply suggestions from code review Co-authored-by: Mitchell Crompton <[email protected]> * added more names to getusers-api-alternative demo * Update changelog.md --------- Co-authored-by: Mitchell Crompton <[email protected]>
1 parent b38dfd5 commit b7f158c

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/
88

99
### 2024-02-13
1010

11+
- DOC-2174: added documentation for Mentions plugin's `getUsers` API deprecation to `6.0-release-notes-premium-changes.adoc` and `migration-from-5x.adoc`.
1112
- DOC-2162: Improve documentation for `noneditable` options and multi-root editing.
1213

1314
### 2024-02-09
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<textarea id="getusers-api-alternative">
2+
<p>The deprecated <code>getUsers</code> API would return an array of currently mentioned names which were mentioned since loading the editor.</p>
3+
<p>Add some mentions to the content by typing "@a...", then click the <strong>getUsers</strong> button in the toolbar to insert a list of names which have been mentioned.</p>
4+
5+
<br><br><br>
6+
7+
<h2>Found a bug?</h2>
8+
9+
<p>If you believe you have found a bug please create an issue on the <a href="https://github.com/tinymce/tinymce/issues">GitHub repo</a> to report it to the developers.</p>
10+
11+
<h2>Finally…</h2>
12+
13+
<p>Don’t forget to check out <a href="http://www.plupload.com" target="_blank">Plupload</a>, the upload solution featuring HTML5 upload support.</p>
14+
<p>Thanks for supporting TinyMCE. We hope it helps you and your users create great content.</p>
15+
<p>All the best from the TinyMCE team.</p>
16+
</textarea>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const users = [
2+
{ id: 'user-1', name: 'Angelina Winn' },
3+
{ id: 'user-2', name: 'Rodrigo Hawkins' },
4+
{ id: 'user-3', name: 'Dianna Smiley' },
5+
{ id: 'user-4', name: 'Eliana Stout' },
6+
{ id: 'user-5', name: 'Oscar Khan' },
7+
{ id: 'user-6', name: 'Mariana Dickey' },
8+
{ id: 'user-7', name: 'Jakoby Roman' },
9+
{ id: 'user-8', name: 'Grace Gross' },
10+
{ id: 'user-9', name: 'Muhammed Sizemore' },
11+
{ id: 'user-10', name: 'Kathryn Mcgee' },
12+
];
13+
14+
const fetchMentions = (query, success) => {
15+
const matches = users.filter((user) => user.name.toLowerCase().includes(query.term.toLowerCase()));
16+
success(matches);
17+
};
18+
19+
const insertedUsers = new Set();
20+
21+
const mentionsInsert = (editor, user) => {
22+
const span = editor.getDoc().createElement('span');
23+
span.className = 'mention';
24+
span.appendChild(editor.getDoc().createTextNode('@' + user.name));
25+
insertedUsers.add(user);
26+
return span;
27+
};
28+
29+
const getUsers = (editor) => {
30+
const spans = Array.from(editor.getBody().querySelectorAll('[data-mce-mentions-id]'));
31+
const currentIds = spans.map((elm) => elm.getAttribute('data-mce-mentions-id'));
32+
const currentUsers = Array.from(insertedUsers).filter((user) => currentIds.includes(user.id));
33+
34+
return currentUsers;
35+
};
36+
37+
tinymce.init({
38+
selector: "textarea#getusers-api-alternative",
39+
plugins: "mentions code",
40+
mentions_fetch: fetchMentions,
41+
mentions_menu_complete: mentionsInsert,
42+
43+
toolbar: 'getUsersButton',
44+
setup: function (editor) {
45+
editor.ui.registry.addButton('getUsersButton', {
46+
text: 'getUsers',
47+
onAction: function () {
48+
// Get mentioned users
49+
var mentionedUsers = getUsers(editor);
50+
// Insert mentioned users as a bullet list
51+
if (mentionedUsers.length > 0) {
52+
var userList = mentionedUsers.map((user) => '<li>' + user.name + '</li>').join('');
53+
editor.execCommand('mceInsertContent', false, '<ul>' + userList + '</ul>');
54+
}
55+
}
56+
});
57+
}
58+
});

modules/ROOT/pages/6.0-release-notes-premium-changes.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ The following change was made to the xref:mentions.adoc[Mentions] plugin:
172172

173173
The `getUsers` API was removed.
174174

175+
View the following demo for an alternative to the `getUsers` API:
176+
177+
liveDemo::getusers-api-alternative[height="400"]
175178

176179
=== PowerPaste
177180

modules/ROOT/pages/migration-from-5x.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ The schema must, therefore, be configured to allow usage of the media elements,
309309

310310
NOTE: As of this release, there are no known cases of this change causing media objects to not work as expected. But, also as of this release, not every potential or possible use-case has been tested.
311311

312+
=== Mentions
313+
314+
The `getUsers` API was a part of the `mentions` plugin and was used to retrieve a list of mentioned users in the current editor session.
315+
316+
This API has been _deprecated_ in {productname} 6.0.
317+
318+
Refer to the xref:6.0-release-notes-premium-changes.adoc#mentions[_{productname} 6.0 Release Notes_] for an alternative to the `getUsers` API.
319+
312320
[[plugins-paste]]
313321
=== Paste
314322

0 commit comments

Comments
 (0)