The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Remove anchor stuff
Tim Wilson9f51b38f8f88
diff --git a/packages/embeds/core/src/anchor.ts b/packages/embeds/core/src/anchor.tsdeleted file mode 100644index 76d464819e..0000000000--- a/packages/embeds/core/src/anchor.ts+++ /dev/null@@ -1,43 +0,0 @@-import { computePosition, offset, Placement, shift } from "@floating-ui/dom";-import { DUB_CONTAINER_ID } from "./constants";-import { DubOptions } from "./types";--export function setAnchoredPosition({- prefix,- anchorId,- placement,-}: { prefix?: string } & Pick<DubOptions, "anchorId" | "placement">) {- if (!anchorId) return;-- const anchor = document.getElementById(anchorId);- if (!anchor) {- console.error(`[Dub] No anchor found with id: ${anchorId}`);- return;- }-- const container = document.getElementById(`${prefix}${DUB_CONTAINER_ID}`);- if (!container) {- console.error(- `[Dub] No container found with id: ${prefix}${DUB_CONTAINER_ID}`,- );- return;- }-- computePosition(anchor, container, {- placement: {- "top-left": "bottom-start",- center: "bottom-start",- "bottom-left": "top-start",- "top-right": "bottom-end",- "bottom-right": "top-end",- }[placement ?? "bottom-right"] as Placement,- middleware: [shift(), offset(16)],- }).then(({ x, y }) => {- Object.assign(container.style, {- top: `${y}px`,- left: `${x}px`,- right: "auto",- bottom: "auto",- });- });-}diff --git a/packages/embeds/core/src/core.ts b/packages/embeds/core/src/core.tsindex 2304a373af..8f7e33748b 100644--- a/packages/embeds/core/src/core.ts+++ b/packages/embeds/core/src/core.ts@@ -1,4 +1,3 @@-import { setAnchoredPosition } from "./anchor";import {CLOSE_ICON,DUB_CLOSE_BUTTON_ID,@@ -64,18 +63,16 @@ const CONTAINER_STYLES = ({const POPUP_STYLES = ({placement,- anchor,}: {placement: DubWidgetPlacement;- anchor: boolean;}): Partial<CSSStyleDeclaration> => ({- width: anchor ? "100%" : "calc(100% - 32px)",+ width: "calc(100% - 32px)",height: "100dvh",- maxHeight: anchor ? "500px" : "532px",+ maxHeight: "532px",backgroundColor: "white",borderRadius: "12px",boxShadow: "0px 8px 30px rgba(0, 0, 0, 0.12), 0px 2px 4px rgba(0, 0, 0, 0.1)",- margin: anchor ? undefined : "16px",+ margin: "16px",overflow: "hidden",...{"bottom-right": { transformOrigin: "bottom right" },@@ -130,8 +127,6 @@ const renderWidget = (placement,containerStyles,popupStyles,- anchorId,- onOpen,onClose,onError,onTokenExpired,@@ -177,7 +172,6 @@ const renderWidget = (Object.assign(popup.style, {...POPUP_STYLES({placement: placement ?? "bottom-right",- anchor: !!anchorId,}),...popupStyles,display: "none",@@ -218,17 +212,7 @@ const renderWidget = (document.body.appendChild(container);- let updatePosition: (() => void) | undefined;-- if (anchorId) {- updatePosition = () => setAnchoredPosition({ prefix, anchorId, placement });- updatePosition();- window.addEventListener("resize", updatePosition);- }-- onOpen?.();-- return { container, updatePosition };+ return { container };};/**@@ -358,7 +342,7 @@ export const init = (options: DubOptions): DubInitResult => {const prefix = options.id ? `${options.id}-` : "";- const { container, updatePosition } = renderWidget(options, {+ const { container } = renderWidget(options, {prefix,closeWidget: closeWidget(prefix),});@@ -380,18 +364,14 @@ export const init = (options: DubOptions): DubInitResult => {}return {- openWidget: openWidget(prefix, updatePosition),+ openWidget: openWidget(prefix),closeWidget: closeWidget(prefix),- toggleWidget: toggleWidget(prefix, updatePosition),+ toggleWidget: toggleWidget(prefix),isWidgetOpen: isWidgetOpen(prefix),destroy: () => {document.querySelectorAll("#" + CSS.escape(`${prefix}${DUB_CONTAINER_ID}`)).forEach((c) => c.remove());-- if (updatePosition) {- window.removeEventListener("resize", updatePosition);- }},};};diff --git a/packages/embeds/core/src/types.ts b/packages/embeds/core/src/types.tsindex fd8d495101..c65eb1ad18 100644--- a/packages/embeds/core/src/types.ts+++ b/packages/embeds/core/src/types.ts@@ -35,9 +35,6 @@ export type DubOptions = {// The placement of the widgetplacement?: DubWidgetPlacement;- // The ID of the anchor element- anchorId?: string;-// The styles for the widget containercontainerStyles?: Partial<CSSStyleDeclaration>;popupStyles?: Partial<CSSStyleDeclaration>;