Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
louisgv committed Mar 7, 2024
1 parent 9b51f43 commit 119f3e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 6 additions & 3 deletions cli/plasmo/src/type.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<ManifestContentScript>, "js">

Expand Down Expand Up @@ -34,7 +35,7 @@ type PlasmoCSUIOverlayAnchor = {
type PlasmoCSUIInlineAnchor = {
element: Element
type: "inline"
insertPosition?: InsertPosition,
insertPosition?: InsertPosition
root?: Root
}

Expand Down Expand Up @@ -78,7 +79,9 @@ export type PlasmoGetOverlayAnchor = GetElement
export type PlasmoGetOverlayAnchorList = Getter<NodeList>

export type PlasmoGetInlineAnchor = GetElement | GetElementInsertOptions
export type PlasmoGetInlineAnchorList = Getter<NodeList | ElementInsertOptionsList>
export type PlasmoGetInlineAnchorList = Getter<
NodeList | ElementInsertOptionsList
>

export type PlasmoMountShadowHost = (
props: {
Expand Down
21 changes: 12 additions & 9 deletions cli/plasmo/templates/static/common/csui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ async function injectAnchor<T>(
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)
}
Expand Down Expand Up @@ -158,7 +161,7 @@ export function createAnchorObserver<T>(Mount: PlasmoCSUI<T>) {

// 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") {
Expand All @@ -169,7 +172,7 @@ export function createAnchorObserver<T>(Mount: PlasmoCSUI<T>) {
}
} else {
const anchor = mountState.hostMap.get(el)
anchor.root?.unmount();
anchor.root?.unmount()
mountState.hostSet.delete(el)
}
}
Expand All @@ -193,8 +196,8 @@ export function createAnchorObserver<T>(Mount: PlasmoCSUI<T>) {
})
}
} else if (
inlineAnchor.element instanceof Element
&& !mountedInlineAnchorSet.has(inlineAnchor.element)
inlineAnchor.element instanceof Element &&
!mountedInlineAnchorSet.has(inlineAnchor.element)
) {
renderList.push({
element: inlineAnchor.element,
Expand All @@ -207,16 +210,16 @@ export function createAnchorObserver<T>(Mount: PlasmoCSUI<T>) {
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,
Expand Down

0 comments on commit 119f3e7

Please sign in to comment.