2 * Provides mention support for users and groups.
4 * @author Alexander Ebert
5 * @copyright 2001-2023 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
8 * @woltlabExcludeBundle tiny
10 define(["require", "exports", "../../Ajax/Backend", "../../Dom/Util", "./Event"], function (require
, exports
, Backend_1
, Util_1
, Event_1
) {
12 Object
.defineProperty(exports
, "__esModule", { value
: true });
13 exports
.setup
= void 0;
14 async
function getPossibleMentions(query
) {
15 // Prevent excessive attempts to resolve mentions.
16 if (query
.length
> 24) {
19 // TODO: Provide the URL as a parameter.
20 const url
= new URL(window
.WSC_API_URL
+ "index.php?editor-get-mention-suggestions/");
21 url
.searchParams
.set("query", query
);
22 const result
= (await (0, Backend_1
.prepareRequest
)(url
.toString())
25 .disableLoadingIndicator()
27 return result
.map((item
) => {
28 if (item
.type
=== "user") {
30 id
: `@${item.username}`,
31 text
: `@${item.username}`,
33 objectId
: item
.userID
,
40 text
: `@${item.name}`,
41 icon
: '<fa-icon name="users"></fa-icon>',
42 objectId
: item
.groupID
,
48 function getMentionConfiguration() {
52 feed
: (query
) => getPossibleMentions(query
),
53 itemRenderer
: (item
) => {
54 return (0, Util_1
.createFragmentFromHtml
)(`
55 <span class="ckeditor5__mention">${item.icon} ${item.text}</span>
64 function setup(element
) {
65 (0, Event_1
.listenToCkeditor
)(element
).setupConfiguration(({ configuration
, features
}) => {
66 if (!features
.mention
) {
69 configuration
.mention
= getMentionConfiguration();
72 exports
.setup
= setup
;