Files
gitea/web_src/js/features/tribute.ts
Sebastian Ertz 3f3bebda0d Update go js dependencies (#37312)
| go | from | to |
| --- | --- | --- |
| github.com/aws/aws-sdk-go-v2/credentials | `1.19.14` | `1.19.15` |
| github.com/aws/aws-sdk-go-v2/service/codecommit | `1.33.12` |
`1.33.13` |
| github.com/dlclark/regexp2 | `1.11.5` | `1.12.0` |
| github.com/go-co-op/gocron/v2 | `2.20.0` | `2.21.0` |
| github.com/go-webauthn/webauthn | `0.16.4` | `0.16.5` |

| js | from | to |
| --- | --- | --- |
| @codemirror/view | `6.41.0` | `6.41.1` |
| @primer/octicons | `19.24.0` | `19.24.1` |
| clippie | `4.1.10` | `4.1.14` |
| postcss | `8.5.9` | `8.5.10` |
| rolldown-license-plugin | `2.2.5` | `3.0.1` |
| swagger-ui-dist | `5.32.2` | `5.32.4` |
| vite | `8.0.8` | `8.0.9` |
| @typescript-eslint/parser | `8.58.2` | `8.59.0` |
| @vitest/eslint-plugin | `1.6.15` | `1.6.16` |
| eslint | `10.2.0` | `10.2.1` |
| eslint-plugin-playwright | `2.10.1` | `2.10.2` |
| eslint-plugin-sonarjs | `4.0.2` | `4.0.3` |
| happy-dom | `20.8.9` | `20.9.0` |
| stylelint | `17.7.0` | `17.8.0` |
| typescript | `6.0.2` | `6.0.3` |
| typescript-eslint | `8.58.2` | `8.59.0` |
| updates | `17.15.3` | `17.15.5` |
| vue-tsc | `3.2.6` | `3.2.7` |

Co-authored-by: Nicolas <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: silverwind <silv3rwind@gmail.com>
Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
2026-04-20 22:32:45 +00:00

61 lines
2.1 KiB
TypeScript

import {emojiKeys, emojiHTML, emojiString} from './emoji.ts';
import {html, htmlRaw} from '../utils/html.ts';
import {fetchMentions} from '../utils/match.ts';
import type {TributeCollection} from 'tributejs';
import type {Mention} from '../types.ts';
export async function attachTribute(element: HTMLElement) {
const {default: Tribute} = await import('tributejs');
const mentionsUrl = element.closest('[data-mentions-url]')?.getAttribute('data-mentions-url');
const emojiCollection: TributeCollection<string> = { // emojis
trigger: ':',
requireLeadingSpace: true,
values: (query: string, cb: (matches: Array<string>) => void) => {
const matches = [];
for (const name of emojiKeys) {
if (name.includes(query)) {
matches.push(name);
if (matches.length > 5) break;
}
}
cb(matches);
},
lookup: (item) => item,
selectTemplate: (item) => {
if (item === undefined) return '';
return emojiString(item.original) ?? '';
},
menuItemTemplate: (item) => {
return html`<div class="tribute-item">${htmlRaw(emojiHTML(item.original))}<span>${item.original}</span></div>`;
},
};
const mentionCollection: TributeCollection<Mention> = {
values: async (_query: string, cb: (matches: Mention[]) => void) => { // eslint-disable-line @typescript-eslint/no-misused-promises
cb(mentionsUrl ? await fetchMentions(mentionsUrl) : []);
},
requireLeadingSpace: true,
menuItemTemplate: (item) => {
const fullNameHtml = item.original.fullname && item.original.fullname !== '' ? html`<span class="fullname">${item.original.fullname}</span>` : '';
return html`
<div class="tribute-item">
<img alt src="${item.original.avatar}" width="21" height="21"/>
<span class="name">${item.original.name}</span>
${htmlRaw(fullNameHtml)}
</div>
`;
},
};
const tribute = new Tribute({
collection: [
emojiCollection,
mentionCollection,
] as TributeCollection<any>[],
noMatchTemplate: () => '',
});
tribute.attach(element);
return tribute;
}