-
-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: CSUI multiple inline and overlay anchors #260
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
924d749
Initial refactor of CSUI mount, ready to test multiple anchors
louisgv a0ccfce
Merge branch 'main' into 198-rfc-csui-mounting-into-multiple-element
louisgv ff7938f
bump config
louisgv 5c7c786
fix absolute path spec
louisgv f44041a
Single anchor working as before
louisgv 0e25239
overlay and inline both working correctly, time to test out multiple
louisgv 9e0acd8
multiple overlay anchor done
louisgv 0ab8bd9
Implement csui container for vanilla cases
louisgv f2d317e
bump canary
louisgv b6583d4
chore: bump deps
louisgv 2b5de62
bump pnpm version
louisgv 775c08e
Update cli/plasmo/src/features/manifest-factory/create-manifest.ts
louisgv cd53edf
fix minor bug
louisgv 7c0dc4c
Merge branch '198-rfc-csui-mounting-into-multiple-element' of github.…
louisgv 798e63d
bump canary
louisgv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
cli/plasmo/templates/static/common/csui-container-react.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from "react" | ||
|
||
import type { PlasmoCSUIContainerProps } from "~type" | ||
|
||
export const OverlayCSUIContainer = (props: PlasmoCSUIContainerProps) => { | ||
const [top, setTop] = React.useState(0) | ||
const [left, setLeft] = React.useState(0) | ||
|
||
React.useEffect(() => { | ||
// Handle overlay repositioning | ||
if (props.anchor.type !== "overlay") { | ||
return | ||
} | ||
|
||
const updatePosition = async () => { | ||
const rect = props.anchor.element.getBoundingClientRect() | ||
|
||
if (!rect) { | ||
return | ||
} | ||
|
||
const pos = { | ||
left: rect.left + window.scrollX, | ||
top: rect.top + window.scrollY | ||
} | ||
|
||
setLeft(pos.left) | ||
setTop(pos.top) | ||
} | ||
|
||
updatePosition() | ||
|
||
const unwatch = props.watchOverlayAnchor?.(updatePosition) | ||
window.addEventListener("scroll", updatePosition) | ||
|
||
return () => { | ||
unwatch?.() | ||
window.removeEventListener("scroll", updatePosition) | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div | ||
id={props.id} | ||
className="plasmo-csui-container" | ||
style={{ | ||
display: "flex", | ||
position: "absolute", | ||
top, | ||
left | ||
}}> | ||
{props.children} | ||
</div> | ||
) | ||
} | ||
|
||
export const InlineCSUIContainer = (props: PlasmoCSUIContainerProps) => ( | ||
<div | ||
id="plasmo-inline" | ||
className="plasmo-csui-container" | ||
style={{ | ||
display: "flex", | ||
position: "relative", | ||
top: 0, | ||
left: 0 | ||
}}> | ||
{props.children} | ||
</div> | ||
) |
54 changes: 54 additions & 0 deletions
54
cli/plasmo/templates/static/common/csui-container-vanilla.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import type { PlasmoCSUIContainerProps } from "~type" | ||
|
||
export const createOverlayCSUIContainer = (props: PlasmoCSUIContainerProps) => { | ||
const container = document.createElement("div") | ||
container.className = "plasmo-csui-container" | ||
container.id = props.id | ||
|
||
container.style.cssText = ` | ||
display: flex; | ||
position: relative; | ||
top: 0px; | ||
left: 0px; | ||
` | ||
|
||
if (props.anchor.type === "overlay") { | ||
const updatePosition = async () => { | ||
const rect = props.anchor.element.getBoundingClientRect() | ||
|
||
if (!rect) { | ||
return | ||
} | ||
|
||
const pos = { | ||
left: rect.left + window.scrollX, | ||
top: rect.top + window.scrollY | ||
} | ||
|
||
container.style.top = `${pos.top}px` | ||
container.style.left = `${pos.left}px` | ||
} | ||
|
||
updatePosition() | ||
|
||
props.watchOverlayAnchor?.(updatePosition) | ||
window.addEventListener("scroll", updatePosition) | ||
} | ||
|
||
return container | ||
} | ||
|
||
export const createInlineCSUIContainer = (props: PlasmoCSUIContainerProps) => { | ||
const container = document.createElement("div") | ||
container.className = "plasmo-csui-container" | ||
container.id = "plasmo-inline" | ||
|
||
container.style.cssText = ` | ||
display: flex; | ||
position: relative; | ||
top: 0px; | ||
left: 0px; | ||
` | ||
|
||
return container | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the first parameter need to be required? I was wondering how we'd use this if we're not mounting into multiple elements, like in the following example.
https://github.com/PlasmoHQ/examples/blob/b3f699d537c5143c928ede46586901bff1cfca62/with-content-scripts-ui/contents/plasmo-root-container.tsx