Skip to content

Commit

Permalink
feat: Add position option for inline insertion (#790)
Browse files Browse the repository at this point in the history
* Add position option for inline insertion

* Changed PlasmoCSUIAnchor to use a Discriminating Union
  • Loading branch information
dvvolynkin authored Nov 9, 2023
1 parent 53aac96 commit 6017ec5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions cli/plasmo/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ type Getter<T, P = any> = (props?: P) => Async<T>

type GetElement = Getter<Element>

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
}
Expand Down
2 changes: 1 addition & 1 deletion cli/plasmo/templates/static/common/csui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function injectAnchor<T>(
mountState
})
} else if (anchor.type === "inline") {
anchor.element.insertAdjacentElement("afterend", shadowHost)
anchor.element.insertAdjacentElement(anchor.insertPosition || "afterend", shadowHost)
} else {
document.documentElement.prepend(shadowHost)
}
Expand Down

1 comment on commit 6017ec5

@ViktorTassen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to use insertPosition with PlasmoCSUIInlineAnchor? Please explain

Please sign in to comment.