diff --git a/apps/web/package.json b/apps/web/package.json index db03aa6557..6b64996e38 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -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", diff --git a/apps/web/src/Linkify.tsx b/apps/web/src/Linkify.tsx index be007a5cb4..2e38c26a33 100644 --- a/apps/web/src/Linkify.tsx +++ b/apps/web/src/Linkify.tsx @@ -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, }; /** diff --git a/apps/web/test/unit-tests/linkify-matrix-test.ts b/apps/web/test/unit-tests/linkify-matrix-test.ts index 38e5c091a0..8e1fd60754 100644 --- a/apps/web/test/unit-tests/linkify-matrix-test.ts +++ b/apps/web/test/unit-tests/linkify-matrix-test.ts @@ -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(); diff --git a/packages/shared-components/src/utils/LinkedText/LinkedText.stories.tsx b/packages/shared-components/src/utils/LinkedText/LinkedText.stories.tsx index d722373838..7ee618adf1 100644 --- a/packages/shared-components/src/utils/LinkedText/LinkedText.stories.tsx +++ b/packages/shared-components/src/utils/LinkedText/LinkedText.stories.tsx @@ -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", diff --git a/packages/shared-components/src/utils/linkify.test.ts b/packages/shared-components/src/utils/linkify.test.ts index 0bcc753a7d..a073d8d008 100644 --- a/packages/shared-components/src/utils/linkify.test.ts +++ b/packages/shared-components/src/utils/linkify.test.ts @@ -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 = {