Fix @calcom/embed-react installation with TS project (#2870)
This commit is contained in:
1 parent
d6678f9b3a
commit
445cdd7cbf
41 files changed
+171
-107
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { CalWindow } from "@calcom/embed-snippet";
|
||||
|
||||
import { CalWindow } from "../embed";
|
||||
import getFloatingButtonHtml from "./FloatingButtonHtml";
|
||||
|
||||
export class FloatingButton extends HTMLElement {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { CalWindow } from "@calcom/embed-snippet";
|
||||
|
||||
import { CalWindow } from "../embed";
|
||||
import loaderCss from "../loader.css";
|
||||
import { getErrorString } from "../utils";
|
||||
import inlineHtml from "./inlineHtml";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { CalWindow } from "@calcom/embed-snippet";
|
||||
|
||||
import { CalWindow } from "../embed";
|
||||
import loaderCss from "../loader.css";
|
||||
import { getErrorString } from "../utils";
|
||||
import modalBoxHtml from "./ModalBoxHtml";
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import type { CalWindow } from "@calcom/embed-snippet";
|
||||
|
||||
import { FloatingButton } from "./FloatingButton/FloatingButton";
|
||||
import { Inline } from "./Inline/inline";
|
||||
import { ModalBox } from "./ModalBox/ModalBox";
|
||||
@@ -11,8 +9,7 @@ import allCss from "./tailwind.generated.css";
|
||||
// HACK: Redefine and don't import WEBAPP_URL as it causes import statement to be present in built file.
|
||||
// This is happening because we are not able to generate an App and a lib using single Vite Config.
|
||||
const WEBAPP_URL =
|
||||
(import.meta.env.NEXT_PUBLIC_WEBAPP_URL_TYPO as string) ||
|
||||
`https://${import.meta.env.NEXT_PUBLIC_VERCEL_URL}`;
|
||||
import.meta.env.EMBED_PUBLIC_WEBAPP_URL || `https://${import.meta.env.EMBED_PUBLIC_VERCEL_URL}`;
|
||||
|
||||
customElements.define("cal-modal-box", ModalBox);
|
||||
customElements.define("cal-floating-button", FloatingButton);
|
||||
@@ -33,7 +30,7 @@ if (!globalCal || !globalCal.q) {
|
||||
// Store Commit Hash to know exactly what version of the code is running
|
||||
// TODO: Ideally it should be the version as per package.json and then it can be renamed to version.
|
||||
// But because it is built on local machine right now, it is much more reliable to have the commit hash.
|
||||
globalCal.fingerprint = import.meta.env.NEXT_PUBLIC_EMBED_FINGER_PRINT as string;
|
||||
globalCal.fingerprint = import.meta.env.EMBED_PUBLIC_EMBED_FINGER_PRINT as string;
|
||||
globalCal.__css = allCss;
|
||||
document.head.appendChild(document.createElement("style")).innerHTML = css;
|
||||
|
||||
@@ -512,6 +509,24 @@ export class Cal {
|
||||
}
|
||||
}
|
||||
|
||||
export interface GlobalCal {
|
||||
(methodName: string, arg?: any): void;
|
||||
/** Marks that the embed.js is loaded. Avoids re-downloading it. */
|
||||
loaded?: boolean;
|
||||
/** Maintains a queue till the time embed.js isn't loaded */
|
||||
q?: InstructionQueue;
|
||||
/** If user registers multiple namespaces, those are available here */
|
||||
ns?: Record<string, GlobalCal>;
|
||||
instance?: Cal;
|
||||
__css?: string;
|
||||
fingerprint?: string;
|
||||
__logQueue?: any[];
|
||||
}
|
||||
|
||||
export interface CalWindow extends Window {
|
||||
Cal?: GlobalCal;
|
||||
}
|
||||
|
||||
globalCal.instance = new Cal("", globalCal.q!);
|
||||
|
||||
for (const [ns, api] of Object.entries(globalCal.ns!)) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { CalWindow } from "@calcom/embed-snippet";
|
||||
import { CalWindow } from "./embed";
|
||||
|
||||
const WEBAPP_URL =
|
||||
import.meta.env.NEXT_PUBLIC_WEBAPP_URL || `https://${import.meta.env.NEXT_PUBLIC_VERCEL_URL}`;
|
||||
const EMBED_LIB_URL = import.meta.env.NEXT_PUBLIC_EMBED_LIB_URL || `${WEBAPP_URL}/embed/embed.js`;
|
||||
import.meta.env.EMBED_PUBLIC_WEBAPP_URL || `https://${import.meta.env.EMBED_PUBLIC_VERCEL_URL}`;
|
||||
const EMBED_LIB_URL = import.meta.env.EMBED_PUBLIC_EMBED_LIB_URL || `${WEBAPP_URL}/embed/embed.js`;
|
||||
|
||||
(window as any).fingerprint = import.meta.env.NEXT_PUBLIC_EMBED_FINGER_PRINT as string;
|
||||
(window as any).fingerprint = import.meta.env.EMBED_PUBLIC_EMBED_FINGER_PRINT as string;
|
||||
|
||||
// Install Cal Embed Code Snippet
|
||||
(function (C, A, L) {
|
||||
|
||||
Reference in new issue
Block a user