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.
60 lines
1.9 KiB
60 lines
1.9 KiB
2 years ago
|
import {matchEmoji, matchMention} from '../../utils/match.js';
|
||
|
import {emojiString} from '../emoji.js';
|
||
|
|
||
|
export function initTextExpander(expander) {
|
||
|
expander?.addEventListener('text-expander-change', ({detail: {key, provide, text}}) => {
|
||
|
if (key === ':') {
|
||
|
const matches = matchEmoji(text);
|
||
|
if (!matches.length) return provide({matched: false});
|
||
|
|
||
|
const ul = document.createElement('ul');
|
||
|
ul.classList.add('suggestions');
|
||
|
for (const name of matches) {
|
||
|
const emoji = emojiString(name);
|
||
|
const li = document.createElement('li');
|
||
|
li.setAttribute('role', 'option');
|
||
|
li.setAttribute('data-value', emoji);
|
||
|
li.textContent = `${emoji} ${name}`;
|
||
|
ul.append(li);
|
||
|
}
|
||
|
|
||
|
provide({matched: true, fragment: ul});
|
||
|
} else if (key === '@') {
|
||
|
const matches = matchMention(text);
|
||
|
if (!matches.length) return provide({matched: false});
|
||
|
|
||
|
const ul = document.createElement('ul');
|
||
|
ul.classList.add('suggestions');
|
||
|
for (const {value, name, fullname, avatar} of matches) {
|
||
|
const li = document.createElement('li');
|
||
|
li.setAttribute('role', 'option');
|
||
|
li.setAttribute('data-value', `${key}${value}`);
|
||
|
|
||
|
const img = document.createElement('img');
|
||
|
img.src = avatar;
|
||
|
li.append(img);
|
||
|
|
||
|
const nameSpan = document.createElement('span');
|
||
|
nameSpan.textContent = name;
|
||
|
li.append(nameSpan);
|
||
|
|
||
|
if (fullname && fullname.toLowerCase() !== name) {
|
||
|
const fullnameSpan = document.createElement('span');
|
||
|
fullnameSpan.classList.add('fullname');
|
||
|
fullnameSpan.textContent = fullname;
|
||
|
li.append(fullnameSpan);
|
||
|
}
|
||
|
|
||
|
ul.append(li);
|
||
|
}
|
||
|
|
||
|
provide({matched: true, fragment: ul});
|
||
|
}
|
||
|
});
|
||
|
expander?.addEventListener('text-expander-value', ({detail}) => {
|
||
|
if (detail?.item) {
|
||
|
detail.value = detail.item.getAttribute('data-value');
|
||
|
}
|
||
|
});
|
||
|
}
|