From e1982f265ef43cd63dd7120b0ae6547e28b14d07 Mon Sep 17 00:00:00 2001 From: Ajay Date: Fri, 30 Jun 2023 02:46:27 -0400 Subject: [PATCH] Move maze utils to a submodule, move tooltip out --- .gitmodules | 3 + maze-utils | 1 + src/components/TooltipComponent.tsx | 35 ------- src/maze-utils | 1 + src/render/GenericNotice.tsx | 3 +- src/render/Tooltip.tsx | 153 +--------------------------- src/types.ts | 5 - webpack/webpack.common.js | 3 +- 8 files changed, 12 insertions(+), 192 deletions(-) create mode 160000 maze-utils delete mode 100644 src/components/TooltipComponent.tsx create mode 120000 src/maze-utils diff --git a/.gitmodules b/.gitmodules index f8e6a71f..19ee9032 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "public/_locales"] path = public/_locales url = https://github.com/ajayyy/ExtensionTranslations +[submodule "maze-utils"] + path = maze-utils + url = https://github.com/ajayyy/maze-utils diff --git a/maze-utils b/maze-utils new file mode 160000 index 00000000..6c30e099 --- /dev/null +++ b/maze-utils @@ -0,0 +1 @@ +Subproject commit 6c30e0993198ec6918d620b34ab03bb0c7fc116f diff --git a/src/components/TooltipComponent.tsx b/src/components/TooltipComponent.tsx deleted file mode 100644 index 0e13c63c..00000000 --- a/src/components/TooltipComponent.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import * as React from "react"; - -export interface TooltipProps { - text: string; - show: boolean; -} - -export interface TooltipState { - -} - -class TooltipComponent extends React.Component { - - constructor(props: TooltipProps) { - super(props); - } - - render(): React.ReactElement { - const style: React.CSSProperties = { - display: this.props.show ? "flex" : "none", - position: "absolute", - } - - return ( - - - {this.props.text} - - - ); - } -} - -export default TooltipComponent; diff --git a/src/maze-utils b/src/maze-utils new file mode 120000 index 00000000..a31448d9 --- /dev/null +++ b/src/maze-utils @@ -0,0 +1 @@ +../maze-utils/src/ \ No newline at end of file diff --git a/src/render/GenericNotice.tsx b/src/render/GenericNotice.tsx index f3cc7a2e..d3dc4f95 100644 --- a/src/render/GenericNotice.tsx +++ b/src/render/GenericNotice.tsx @@ -5,8 +5,9 @@ import NoticeComponent from "../components/NoticeComponent"; import Utils from "../utils"; const utils = new Utils(); -import { ButtonListener, ContentContainer } from "../types"; +import { ContentContainer } from "../types"; import NoticeTextSelectionComponent from "../components/NoticeTextSectionComponent"; +import { ButtonListener } from "../../maze-utils/src/components/component-types"; export interface TextBox { icon: string; diff --git a/src/render/Tooltip.tsx b/src/render/Tooltip.tsx index 22e4ab09..d08c0f61 100644 --- a/src/render/Tooltip.tsx +++ b/src/render/Tooltip.tsx @@ -1,154 +1,7 @@ -import * as React from "react"; -import { createRoot, Root } from 'react-dom/client'; -import { ButtonListener } from "../types"; -import { isFirefoxOrSafari } from "@ajayyy/maze-utils"; -import { isSafari } from "@ajayyy/maze-utils/lib/config"; +import { GenericTooltip, TooltipProps } from "../../maze-utils/src/components/Tooltip"; -export interface TooltipProps { - text?: string; - link?: string; - linkOnClick?: () => void; - referenceNode: HTMLElement; - prependElement?: HTMLElement; // Element to append before - bottomOffset?: string; - topOffset?: string; - leftOffset?: string; - rightOffset?: string; - timeout?: number; - opacity?: number; - displayTriangle?: boolean; - extraClass?: string; - showLogo?: boolean; - showGotIt?: boolean; - center?: boolean; - positionRealtive?: boolean; - containerAbsolute?: boolean; - buttons?: ButtonListener[]; -} - -export class Tooltip { - text?: string; - container: HTMLDivElement; - - timer: NodeJS.Timeout; - root: Root; - +export class Tooltip extends GenericTooltip { constructor(props: TooltipProps) { - props.bottomOffset ??= "70px"; - props.topOffset ??= "inherit"; - props.leftOffset ??= "inherit"; - props.rightOffset ??= "inherit"; - props.opacity ??= 0.7; - props.displayTriangle ??= true; - props.extraClass ??= ""; - props.showLogo ??= true; - props.showGotIt ??= true; - props.positionRealtive ??= true; - props.containerAbsolute ??= false; - props.center ??= false; - this.text = props.text; - - this.container = document.createElement('div'); - this.container.id = "sponsorTooltip" + props.text; - if (props.positionRealtive) this.container.style.position = "relative"; - if (props.containerAbsolute) this.container.style.position = "absolute"; - if (props.center) { - if (isFirefoxOrSafari() && !isSafari()) { - this.container.style.width = "-moz-available"; - } else { - this.container.style.width = "-webkit-fill-available"; - } - } - - if (props.prependElement) { - props.referenceNode.insertBefore(this.container, props.prependElement); - } else { - props.referenceNode.appendChild(this.container); - } - - if (props.timeout) { - this.timer = setTimeout(() => this.close(), props.timeout * 1000); - } - - const backgroundColor = `rgba(28, 28, 28, ${props.opacity})`; - - this.root = createRoot(this.container); - this.root.render( -
-
- {props.showLogo ? - - - : null} - {this.text ? - - {this.text + (props.link ? ". " : "")} - {props.link ? - - {chrome.i18n.getMessage("LearnMore")} - - : (props.linkOnClick ? - - {chrome.i18n.getMessage("LearnMore")} - - : null)} - - : null} - - {this.getButtons(props.buttons)} -
- {props.showGotIt ? - - : null} -
- ) - } - - getButtons(buttons?: ButtonListener[]): JSX.Element[] { - if (buttons) { - const result: JSX.Element[] = []; - - for (const button of buttons) { - result.push( - - ) - } - - return result; - } else { - return null; - } - } - - close(): void { - this.root.unmount(); - this.container.remove(); - - if (this.timer) clearTimeout(this.timer); + super(props, "icons/IconSponsorBlocker256px.png") } } \ No newline at end of file diff --git a/src/types.ts b/src/types.ts index 4913fdad..9ea0841c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -220,9 +220,4 @@ export enum NoticeVisbilityMode { MiniForAll = 2, FadedForAutoSkip = 3, FadedForAll = 4 -} - -export interface ButtonListener { - name: string; - listener: (e?: React.MouseEvent) => void; } \ No newline at end of file diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index 171b2885..e1a3e66c 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -123,7 +123,8 @@ module.exports = env => { ] }, resolve: { - extensions: ['.ts', '.tsx', '.js'] + extensions: ['.ts', '.tsx', '.js'], + symlinks: false }, plugins: [ // Prehook to start building document script before normal build