diff --git a/cli/plasmo/src/type.ts b/cli/plasmo/src/type.ts index 16430e1b2..c033b7616 100644 --- a/cli/plasmo/src/type.ts +++ b/cli/plasmo/src/type.ts @@ -1,6 +1,7 @@ -import type { ManifestContentScript } from "@plasmo/constants/manifest/content-script" import type { Root } from "react-dom/client" +import type { ManifestContentScript } from "@plasmo/constants/manifest/content-script" + // See https://www.plasmo.com/engineering/log/2022.04#update-2022.04.23 export type PlasmoCSConfig = Omit, "js"> @@ -34,7 +35,7 @@ type PlasmoCSUIOverlayAnchor = { type PlasmoCSUIInlineAnchor = { element: Element type: "inline" - insertPosition?: InsertPosition, + insertPosition?: InsertPosition root?: Root } @@ -78,7 +79,9 @@ export type PlasmoGetOverlayAnchor = GetElement export type PlasmoGetOverlayAnchorList = Getter export type PlasmoGetInlineAnchor = GetElement | GetElementInsertOptions -export type PlasmoGetInlineAnchorList = Getter +export type PlasmoGetInlineAnchorList = Getter< + NodeList | ElementInsertOptionsList +> export type PlasmoMountShadowHost = ( props: { diff --git a/cli/plasmo/templates/static/common/csui.ts b/cli/plasmo/templates/static/common/csui.ts index 4b3d108df..de04b337c 100644 --- a/cli/plasmo/templates/static/common/csui.ts +++ b/cli/plasmo/templates/static/common/csui.ts @@ -50,7 +50,10 @@ async function injectAnchor( mountState }) } else if (anchor.type === "inline") { - anchor.element.insertAdjacentElement(anchor.insertPosition || "afterend", shadowHost) + anchor.element.insertAdjacentElement( + anchor.insertPosition || "afterend", + shadowHost + ) } else { document.documentElement.prepend(shadowHost) } @@ -158,7 +161,7 @@ export function createAnchorObserver(Mount: PlasmoCSUI) { // Go through mounted sets and check if they are still mounted for (const el of mountState.hostSet) { - if (isMounted(el)) { + if (isMounted(el)) { const anchor = mountState.hostMap.get(el) if (!!anchor) { if (anchor.type === "inline") { @@ -169,7 +172,7 @@ export function createAnchorObserver(Mount: PlasmoCSUI) { } } else { const anchor = mountState.hostMap.get(el) - anchor.root?.unmount(); + anchor.root?.unmount() mountState.hostSet.delete(el) } } @@ -193,8 +196,8 @@ export function createAnchorObserver(Mount: PlasmoCSUI) { }) } } else if ( - inlineAnchor.element instanceof Element - && !mountedInlineAnchorSet.has(inlineAnchor.element) + inlineAnchor.element instanceof Element && + !mountedInlineAnchorSet.has(inlineAnchor.element) ) { renderList.push({ element: inlineAnchor.element, @@ -207,16 +210,16 @@ export function createAnchorObserver(Mount: PlasmoCSUI) { if ((inlineAnchorList?.length || 0) > 0) { inlineAnchorList.forEach((inlineAnchor) => { if ( - inlineAnchor instanceof Element && - !mountedInlineAnchorSet.has(inlineAnchor) + inlineAnchor instanceof Element && + !mountedInlineAnchorSet.has(inlineAnchor) ) { renderList.push({ element: inlineAnchor, type: "inline" }) } else if ( - inlineAnchor.element instanceof Element && - !mountedInlineAnchorSet.has(inlineAnchor.element) + inlineAnchor.element instanceof Element && + !mountedInlineAnchorSet.has(inlineAnchor.element) ) { renderList.push({ element: inlineAnchor.element,