Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix type error

Steven Teyf5d8c08cf0a1
diff --git a/packages/embeds/core/src/core.ts b/packages/embeds/core/src/core.ts
index a2b1800b96..50c4297c02 100644
--- a/packages/embeds/core/src/core.ts
+++ b/packages/embeds/core/src/core.ts
@@ -1,6 +1,6 @@
import { DUB_CONTAINER_ID, EMBED_URL } from "./constants";
import { EmbedError } from "./error";
-import { DubInitResult, DubOptions, IframeMessage } from "./types";
+import { DubEmbedOptions, DubInitResult, IframeMessage } from "./types";
const CONTAINER_STYLES = {
position: "relative",
@@ -10,13 +10,11 @@ const CONTAINER_STYLES = {
};
class DubEmbed {
- options: DubOptions;
- prefix: string;
+ options: DubEmbedOptions;
container: HTMLElement | null;
- constructor(options: DubOptions) {
+ constructor(options: DubEmbedOptions) {
this.options = options;
- this.prefix = options.id ? `${options.id}-` : "";
console.debug("[Dub] Initializing.", options);
@@ -31,9 +29,7 @@ class DubEmbed {
const { token, root, containerStyles, onError } = this.options;
- const existingContainer = document.getElementById(
- `${this.prefix}${DUB_CONTAINER_ID}`,
- );
+ const existingContainer = document.getElementById(DUB_CONTAINER_ID);
if (existingContainer) return existingContainer;
@@ -43,7 +39,7 @@ class DubEmbed {
}
const container = document.createElement("div");
- container.id = `${this.prefix}${DUB_CONTAINER_ID}`;
+ container.id = DUB_CONTAINER_ID;
Object.assign(container.style, {
...CONTAINER_STYLES,
...containerStyles,
@@ -77,7 +73,7 @@ class DubEmbed {
* Destroys the embed, removing any remaining DOM elements.
*/
destroy() {
- document.getElementById(`${this.prefix}${DUB_CONTAINER_ID}`)?.remove();
+ document.getElementById(DUB_CONTAINER_ID)?.remove();
}
}
@@ -97,7 +93,7 @@ const createIframe = (iframeUrl: string, token: string): HTMLIFrameElement => {
/**
* Initializes the Dub embed.
*/
-export const init = (options: DubOptions): DubInitResult => {
+export const init = (options: DubEmbedOptions): DubInitResult => {
const embed = new DubEmbed(options);
return {
diff --git a/packages/embeds/core/src/types.ts b/packages/embeds/core/src/types.ts
index 3dd24b5064..1889156b53 100644
--- a/packages/embeds/core/src/types.ts
+++ b/packages/embeds/core/src/types.ts
@@ -3,10 +3,10 @@ export type DubInitResult = {
} | null;
export interface DubEmbed {
- init: (options: DubOptions) => void;
+ init: (options: DubEmbedOptions) => void;
}
-export type DubOptions = {
+export type DubEmbedOptions = {
// The link token
token: string;
diff --git a/packages/embeds/react/src/embed.tsx b/packages/embeds/react/src/embed.tsx
index bf321bbbf4..797b1f895b 100644
--- a/packages/embeds/react/src/embed.tsx
+++ b/packages/embeds/react/src/embed.tsx
@@ -1,12 +1,12 @@
"use client";
-import { DubOptions, init } from "@dub/embed-core";
+import { DubEmbedOptions, init } from "@dub/embed-core";
import { HTMLProps, memo, useEffect, useId, useRef } from "react";
-type Options = Omit<DubOptions, "token">;
+type Options = Omit<DubEmbedOptions, "token">;
type DubEmbedProps = {
- token: DubOptions["token"];
+ token: DubEmbedOptions["token"];
options?: Options;
} & HTMLProps<HTMLDivElement>;
@@ -17,7 +17,7 @@ export const DubEmbed = memo(({ token, options, ...rest }: DubEmbedProps) => (
function DubInline({
options,
...rest
-}: { options: DubOptions } & HTMLProps<HTMLDivElement>) {
+}: { options: DubEmbedOptions } & HTMLProps<HTMLDivElement>) {
const id = useId();
const rootRef = useRef<HTMLDivElement>(null);
@@ -26,7 +26,6 @@ function DubInline({
const { destroy } =
init({
- id,
root: rootRef.current,
...options,
}) || {};