From 0b24d33c64e5a161621f68fa8da65aaa8d1c847d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 23 Dec 2024 16:12:56 +0000 Subject: [PATCH] Simplify types (#28749) --- package.json | 1 + src/@types/png-chunks-extract.d.ts | 18 ------------------ src/@types/sanitize-html.d.ts | 15 --------------- src/HtmlUtils.tsx | 7 +++---- src/Linkify.tsx | 7 +++---- yarn.lock | 5 +++++ 6 files changed, 12 insertions(+), 41 deletions(-) delete mode 100644 src/@types/png-chunks-extract.d.ts delete mode 100644 src/@types/sanitize-html.d.ts diff --git a/package.json b/package.json index f41993a687..aac1d92518 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "@matrix-org/react-sdk-module-api": "^2.4.0", "@matrix-org/spec": "^1.7.0", "@sentry/browser": "^8.0.0", + "@types/png-chunks-extract": "^1.0.2", "@vector-im/compound-design-tokens": "^2.0.1", "@vector-im/compound-web": "^7.5.0", "@vector-im/matrix-wysiwyg": "2.37.13", diff --git a/src/@types/png-chunks-extract.d.ts b/src/@types/png-chunks-extract.d.ts deleted file mode 100644 index c767b40655..0000000000 --- a/src/@types/png-chunks-extract.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright 2024 New Vector Ltd. -Copyright 2021 The Matrix.org Foundation C.I.C. - -SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only -Please see LICENSE files in the repository root for full details. -*/ - -declare module "png-chunks-extract" { - interface IChunk { - name: string; - data: Uint8Array; - } - - function extractPngChunks(data: Uint8Array): IChunk[]; - - export default extractPngChunks; -} diff --git a/src/@types/sanitize-html.d.ts b/src/@types/sanitize-html.d.ts deleted file mode 100644 index 34474fc655..0000000000 --- a/src/@types/sanitize-html.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* -Copyright 2024 New Vector Ltd. -Copyright 2020 The Matrix.org Foundation C.I.C. - -SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only -Please see LICENSE files in the repository root for full details. -*/ - -import sanitizeHtml from "sanitize-html"; - -export interface IExtendedSanitizeOptions extends sanitizeHtml.IOptions { - // This option only exists in 2.x RCs so far, so not yet present in the - // separate type definition module. - nestingLimit?: number; -} diff --git a/src/HtmlUtils.tsx b/src/HtmlUtils.tsx index 3146a9eb07..f5e30734bb 100644 --- a/src/HtmlUtils.tsx +++ b/src/HtmlUtils.tsx @@ -10,7 +10,7 @@ Please see LICENSE files in the repository root for full details. */ import React, { LegacyRef, ReactNode } from "react"; -import sanitizeHtml from "sanitize-html"; +import sanitizeHtml, { IOptions } from "sanitize-html"; import classNames from "classnames"; import katex from "katex"; import { decode } from "html-entities"; @@ -19,7 +19,6 @@ import { Optional } from "matrix-events-sdk"; import escapeHtml from "escape-html"; import { getEmojiFromUnicode } from "@matrix-org/emojibase-bindings"; -import { IExtendedSanitizeOptions } from "./@types/sanitize-html"; import SettingsStore from "./settings/SettingsStore"; import { stripHTMLReply, stripPlainReply } from "./utils/Reply"; import { PERMITTED_URL_SCHEMES } from "./utils/UrlUtils"; @@ -126,7 +125,7 @@ export function isUrlPermitted(inputUrl: string): boolean { } // this is the same as the above except with less rewriting -const composerSanitizeHtmlParams: IExtendedSanitizeOptions = { +const composerSanitizeHtmlParams: IOptions = { ...sanitizeHtmlParams, transformTags: { "code": transformTags["code"], @@ -135,7 +134,7 @@ const composerSanitizeHtmlParams: IExtendedSanitizeOptions = { }; // reduced set of allowed tags to avoid turning topics into Myspace -const topicSanitizeHtmlParams: IExtendedSanitizeOptions = { +const topicSanitizeHtmlParams: IOptions = { ...sanitizeHtmlParams, allowedTags: [ "font", // custom to matrix for IRC-style font coloring diff --git a/src/Linkify.tsx b/src/Linkify.tsx index d980c496c4..37376cd75a 100644 --- a/src/Linkify.tsx +++ b/src/Linkify.tsx @@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details. */ import React, { ReactElement } from "react"; -import sanitizeHtml from "sanitize-html"; +import sanitizeHtml, { IOptions } from "sanitize-html"; import { merge } from "lodash"; import _Linkify from "linkify-react"; @@ -17,7 +17,6 @@ import { ELEMENT_URL_PATTERN, options as linkifyMatrixOptions, } from "./linkify-matrix"; -import { IExtendedSanitizeOptions } from "./@types/sanitize-html"; import SettingsStore from "./settings/SettingsStore"; import { tryTransformPermalinkToLocalHref } from "./utils/permalinks/Permalinks"; import { mediaFromMxc } from "./customisations/Media"; @@ -26,7 +25,7 @@ import { PERMITTED_URL_SCHEMES } from "./utils/UrlUtils"; const COLOR_REGEX = /^#[0-9a-fA-F]{6}$/; const MEDIA_API_MXC_REGEX = /\/_matrix\/media\/r0\/(?:download|thumbnail)\/(.+?)\/(.+?)(?:[?/]|$)/; -export const transformTags: NonNullable = { +export const transformTags: NonNullable = { // custom to matrix // add blank targets to all hyperlinks except vector URLs "a": function (tagName: string, attribs: sanitizeHtml.Attributes) { @@ -137,7 +136,7 @@ export const transformTags: NonNullable