1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

chore: upgrade to mithril 2.2 (#3831)

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
Sami Mazouz
2023-06-15 18:04:41 +01:00
committed by GitHub
parent 493ffa0538
commit 11b4a810b7
8 changed files with 25 additions and 28 deletions

View File

@@ -15,7 +15,7 @@
"focus-trap": "^6.7.1",
"jquery": "^3.6.0",
"jquery.hotkeys": "^0.1.0",
"mithril": "~2.0.4",
"mithril": "^2.2",
"nanoid": "^3.1.30",
"punycode": "^2.1.1",
"textarea-caret": "^3.1.0",

View File

@@ -15,9 +15,7 @@ export default class Link extends Component {
attrs.href ||= '';
// For some reason, m.route.Link does not like vnode.text, so if present, we
// need to convert it to text vnodes and store it in children.
const children = vnode.children || { tag: '#', children: vnode.text };
const children = vnode.children;
if (attrs.external) {
return <a {...attrs}>{children}</a>;

View File

@@ -1,13 +1,15 @@
import app from '../../common/app';
import type Mithril from 'mithril';
import User from '../models/User';
import extractText from '../utils/extractText';
/**
* The `username` helper displays a user's username in a <span className="username">
* tag. If the user doesn't exist, the username will be displayed as [deleted].
*/
export default function username(user: User | null | undefined | false): Mithril.Vnode {
const name = (user && user.displayName()) || app.translator.trans('core.lib.username.deleted_text');
export default function username(user: User | null | undefined | false, transformer?: (name: string) => Mithril.Children): Mithril.Vnode {
const name = (user && user.displayName()) || extractText(app.translator.trans('core.lib.username.deleted_text'));
const children = transformer ? transformer(name) : name;
return <span className="username">{name}</span>;
return <span className="username">{children}</span>;
}

View File

@@ -7,7 +7,7 @@ export default function extractText(vdom: Mithril.Children): string {
if (vdom instanceof Array) {
return vdom.map((element) => extractText(element)).join('');
} else if (typeof vdom === 'object' && vdom !== null) {
return vdom.children ? extractText(vdom.children) : String(vdom.text);
return extractText(vdom.children);
} else {
return String(vdom);
}

View File

@@ -44,15 +44,13 @@ export default class UsersSearchResults implements SearchSource {
return [
<li className="Dropdown-header">{app.translator.trans('core.forum.search.users_heading')}</li>,
...results.map((user) => {
const name = username(user);
const children = [highlight(name.text as string, query)];
const name = username(user, (name: string) => highlight(name, query));
return (
<li className="UserSearchResult" data-index={'users' + user.id()}>
<Link href={app.route.user(user)}>
{avatar(user)}
{{ ...name, text: undefined, children }}
{name}
</Link>
</li>
);