mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
4 months ago
|
import {emojiKeys, emojiHTML, emojiString} from './emoji.ts';
|
||
2 years ago
|
import {htmlEscape} from 'escape-goat';
|
||
5 years ago
|
|
||
5 years ago
|
function makeCollections({mentions, emoji}) {
|
||
|
const collections = [];
|
||
|
|
||
2 years ago
|
if (emoji) {
|
||
5 years ago
|
collections.push({
|
||
|
trigger: ':',
|
||
|
requireLeadingSpace: true,
|
||
|
values: (query, cb) => {
|
||
|
const matches = [];
|
||
|
for (const name of emojiKeys) {
|
||
|
if (name.includes(query)) {
|
||
|
matches.push(name);
|
||
|
if (matches.length > 5) break;
|
||
|
}
|
||
5 years ago
|
}
|
||
5 years ago
|
cb(matches);
|
||
|
},
|
||
|
lookup: (item) => item,
|
||
|
selectTemplate: (item) => {
|
||
2 years ago
|
if (item === undefined) return null;
|
||
5 years ago
|
return emojiString(item.original);
|
||
|
},
|
||
|
menuItemTemplate: (item) => {
|
||
2 years ago
|
return `<div class="tribute-item">${emojiHTML(item.original)}<span>${htmlEscape(item.original)}</span></div>`;
|
||
8 months ago
|
},
|
||
5 years ago
|
});
|
||
5 years ago
|
}
|
||
|
|
||
2 years ago
|
if (mentions) {
|
||
5 years ago
|
collections.push({
|
||
1 year ago
|
values: window.config.mentionValues ?? [],
|
||
3 years ago
|
requireLeadingSpace: true,
|
||
5 years ago
|
menuItemTemplate: (item) => {
|
||
|
return `
|
||
|
<div class="tribute-item">
|
||
5 months ago
|
<img src="${htmlEscape(item.original.avatar)}" width="21" height="21"/>
|
||
2 years ago
|
<span class="name">${htmlEscape(item.original.name)}</span>
|
||
|
${item.original.fullname && item.original.fullname !== '' ? `<span class="fullname">${htmlEscape(item.original.fullname)}</span>` : ''}
|
||
5 years ago
|
</div>
|
||
|
`;
|
||
8 months ago
|
},
|
||
5 years ago
|
});
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
return collections;
|
||
|
}
|
||
|
|
||
2 years ago
|
export async function attachTribute(element, {mentions, emoji} = {}) {
|
||
5 years ago
|
const {default: Tribute} = await import(/* webpackChunkName: "tribute" */'tributejs');
|
||
2 years ago
|
const collections = makeCollections({mentions, emoji});
|
||
3 years ago
|
const tribute = new Tribute({collection: collections, noMatchTemplate: ''});
|
||
2 years ago
|
tribute.attach(element);
|
||
5 years ago
|
return tribute;
|
||
5 years ago
|
}
|