This commit is contained in:
Half-Shot 2026-03-05 15:59:42 +00:00
parent 385ec6ac37
commit 4384e7cdb2
5 changed files with 10 additions and 20 deletions

View File

@ -78,10 +78,6 @@
"jsrsasign": "^11.0.0",
"jszip": "^3.7.0",
"katex": "^0.16.0",
"linkify-html": "4.3.2",
"linkify-react": "4.3.2",
"linkify-string": "4.3.2",
"linkifyjs": "4.3.2",
"lodash": "npm:lodash-es@^4.17.21",
"maplibre-gl": "^5.0.0",
"matrix-encrypt-attachment": "^1.0.3",

View File

@ -260,7 +260,7 @@ function urlEventListeners(href: string, onClickAction?: () => void): linkifyjs.
return {};
}
function userIdEventListeners(href: string, onClickAction?: () => void): linkifyjs.EventListeners {
export function userIdEventListeners(href: string, onClickAction?: () => void): linkifyjs.EventListeners {
return {
click: function (e: MouseEvent) {
e.preventDefault();
@ -271,7 +271,7 @@ function userIdEventListeners(href: string, onClickAction?: () => void): linkify
};
}
function roomAliasEventListeners(href: string, onClickAction?: () => void): linkifyjs.EventListeners {
export function roomAliasEventListeners(href: string, onClickAction?: () => void): linkifyjs.EventListeners {
return {
click: function (e: MouseEvent) {
e.preventDefault();
@ -282,7 +282,7 @@ function roomAliasEventListeners(href: string, onClickAction?: () => void): link
};
}
function UrlTargetTransformFunction(href: string | string): string {
function urlTargetTransformFunction(href: string | string): string {
try {
const transformed = tryTransformPermalinkToLocalHref(href);
if (
@ -328,7 +328,7 @@ const DefaultLinkifyOptions = {
roomAliasListener: roomAliasEventListeners,
urlListener: urlEventListeners,
hrefTransformer: formatHref,
urlTargetTransformer: UrlTargetTransformFunction,
urlTargetTransformer: urlTargetTransformFunction,
};
/**

View File

@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import type { linkifyjs } from "@element-hq/web-shared-components";
import { options } from "../../src/linkify-matrix";
import { roomAliasEventListeners, userIdEventListeners } from "../../src/Linkify";
import dispatcher from "../../src/dispatcher/dispatcher";
import { Action } from "../../src/dispatcher/actions";
@ -15,11 +15,7 @@ describe("linkify-matrix", () => {
it("should intercept clicks with a ViewRoom dispatch", () => {
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
const handlers = (options.events as (href: string, type: string) => linkifyjs.EventListeners)(
"#room:server.com",
"roomalias",
);
const handlers = roomAliasEventListeners("#room:server.com");
const event = new MouseEvent("mousedown");
event.preventDefault = jest.fn();
handlers!.click(event);
@ -37,10 +33,7 @@ describe("linkify-matrix", () => {
it("should intercept clicks with a ViewUser dispatch", () => {
const dispatchSpy = jest.spyOn(dispatcher, "dispatch");
const handlers = (options.events as (href: string, type: string) => linkifyjs.EventListeners)(
"@localpart:server.com",
"userid",
);
const handlers = userIdEventListeners("@localpart:server.com");
const event = new MouseEvent("mousedown");
event.preventDefault = jest.fn();

View File

@ -5,10 +5,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import React from "react";
import { fn } from "storybook/test";
import type { Meta, StoryFn } from "@storybook/react-vite";
import { LinkedText } from "./LinkedText";
import { fn } from "storybook/test";
export default {
title: "Utils/LinkedText",

View File

@ -7,7 +7,8 @@ Please see LICENSE files in the repository root for full details.
*/
import { describe, it, expect } from "vitest";
import { linkifyjs, LinkifyMatrixOpaqueIdType } from "@element-hq/web-shared-components";
import { linkifyjs, LinkifyMatrixOpaqueIdType } from "./linkify";
describe("linkify-matrix", () => {
const linkTypesByInitialCharacter: Record<string, string> = {