diff --git a/cli/plasmo/src/type.ts b/cli/plasmo/src/type.ts index dafa40d66..a7ae39371 100644 --- a/cli/plasmo/src/type.ts +++ b/cli/plasmo/src/type.ts @@ -14,11 +14,19 @@ type Getter = (props?: P) => Async type GetElement = Getter -export type PlasmoCSUIAnchor = { +type PlasmoCSUIOverlayAnchor = { element: Element - type: "overlay" | "inline" + type: "overlay" } +type PlasmoCSUIInlineAnchor = { + element: Element + type: "inline" + insertPosition?: "beforebegin" | "afterbegin" | "beforeend" | "afterend" +} + +export type PlasmoCSUIAnchor = PlasmoCSUIOverlayAnchor | PlasmoCSUIInlineAnchor + export type PlasmoCSUIProps = { anchor?: PlasmoCSUIAnchor } diff --git a/cli/plasmo/templates/static/common/csui.ts b/cli/plasmo/templates/static/common/csui.ts index a910b9cce..118161bb2 100644 --- a/cli/plasmo/templates/static/common/csui.ts +++ b/cli/plasmo/templates/static/common/csui.ts @@ -50,7 +50,7 @@ async function injectAnchor( mountState }) } else if (anchor.type === "inline") { - anchor.element.insertAdjacentElement("afterend", shadowHost) + anchor.element.insertAdjacentElement(anchor.insertPosition || "afterend", shadowHost) } else { document.documentElement.prepend(shadowHost) }