Fix @calcom/embed-react installation with TS project (#2870)
No files matched your search
@@ -0,0 +1,2 @@
|
||||
export * from "./src/embed-iframe";
|
||||
export * from "./src/sdk-event";
|
||||
@@ -1,7 +1,9 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly NEXT_PUBLIC_WEBSITE_URL: string;
|
||||
readonly EMBED_PUBLIC_WEBAPP_URL: string;
|
||||
readonly EMBED_PUBLIC_VERCEL_URL: string;
|
||||
readonly EMBED_PUBLIC_EMBED_LIB_URL: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from "./src/embed-iframe";
|
||||
export * from "./src/sdk-event";
|
||||
export * from "./src/embed";
|
||||
@@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "@calcom/embed-core",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.0-beta.10",
|
||||
"description": "This is the vanilla JS core script that embeds Cal Link",
|
||||
"main": "./index.ts",
|
||||
"main": "./dist/embed/embed.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"__build": "yarn tailwind && vite build",
|
||||
"__build": "yarn tailwind && vite build && yarn tsc --emitDeclarationOnly --declarationDir dist && cp -r ../../../apps/web/public/embed ./dist/",
|
||||
"__dev": "yarn __build --mode development",
|
||||
"build": "NEXT_PUBLIC_EMBED_FINGER_PRINT=$(git rev-parse --short HEAD) yarn __build",
|
||||
"build-preview": "PREVIEW_BUILD=1 yarn __build ",
|
||||
@@ -16,8 +17,12 @@
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"lint": "eslint --ext .ts,.js src",
|
||||
"embed-tests": "yarn playwright test --config=playwright/config/playwright.config.ts",
|
||||
"embed-tests-quick": "QUICK=true yarn embed-tests"
|
||||
"embed-tests-quick": "QUICK=true yarn embed-tests",
|
||||
"prepare": "NEXT_PUBLIC_WEBAPP_URL='https://app.cal.com' yarn build"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"postcss": {
|
||||
"map": false,
|
||||
"plugins": {
|
||||
@@ -29,11 +34,10 @@
|
||||
"autoprefixer": "^10.4.7",
|
||||
"eslint": "^8.15.0",
|
||||
"postcss": "^8.4.13",
|
||||
"vite": "^2.9.9"
|
||||
},
|
||||
"dependencies": {
|
||||
"vite": "^2.9.9",
|
||||
"tailwindcss": "^3.0.24",
|
||||
"tsc": "^2.0.4",
|
||||
"typescript": "^4.6.4"
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -22,7 +22,8 @@ const config: PlaywrightTestConfig = {
|
||||
expect: {
|
||||
toMatchSnapshot: {
|
||||
// Opacity transitions can cause small differences
|
||||
maxDiffPixels: 50,
|
||||
// Every month the rendered month changes failing the snapshot tests. So, increase the threshold to catch major bugs only.
|
||||
maxDiffPixelRatio: 0.1,
|
||||
},
|
||||
},
|
||||
webServer: {
|
||||
@@ -123,7 +124,7 @@ expect.extend({
|
||||
|
||||
const searchParams = u.searchParams;
|
||||
const expectedSearchParams = expectedUrlDetails.searchParams || {};
|
||||
for (let [expectedKey, expectedValue] of Object.entries(expectedSearchParams)) {
|
||||
for (const [expectedKey, expectedValue] of Object.entries(expectedSearchParams)) {
|
||||
const value = searchParams.get(expectedKey);
|
||||
if (value !== expectedValue) {
|
||||
return {
|
||||
|
||||
@@ -36,7 +36,7 @@ export const getEmbedIframe = async ({ page, pathname }: { page: Page; pathname:
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 2000);
|
||||
});
|
||||
let embedIframe = page.frame("cal-embed");
|
||||
const embedIframe = page.frame("cal-embed");
|
||||
if (!embedIframe) {
|
||||
return null;
|
||||
}
|
||||
@@ -83,7 +83,7 @@ export async function bookFirstEvent(username: string, frame: Frame, page: Page)
|
||||
const responseObj = await response.json();
|
||||
const bookingId = responseObj.uid;
|
||||
// Make sure we're navigated to the success page
|
||||
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
||||
await expect(frame.locator("[data-testid=success-page]")).toBeVisible();
|
||||
expect(await page.screenshot()).toMatchSnapshot("success-page.png");
|
||||
return bookingId;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 259 KiB After Width: | Height: | Size: 259 KiB |
|
Before Width: | Height: | Size: 282 KiB After Width: | Height: | Size: 287 KiB |
|
Before Width: | Height: | Size: 262 KiB After Width: | Height: | Size: 262 KiB |
|
Before Width: | Height: | Size: 353 KiB After Width: | Height: | Size: 313 KiB |
@@ -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) {
|
||||
|
||||
@@ -8,6 +8,6 @@
|
||||
"moduleResolution": "Node",
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["."],
|
||||
"include": ["src", "env.d.ts", "index.ts"],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
require("dotenv").config({ path: "../../../.env" });
|
||||
|
||||
process.env.NEXT_PUBLIC_VERCEL_URL = process.env.VERCEL_URL;
|
||||
import viteBaseConfig from "../vite.config";
|
||||
|
||||
const path = require("path");
|
||||
const { defineConfig } = require("vite");
|
||||
|
||||
module.exports = defineConfig((configEnv) => {
|
||||
const config = {
|
||||
envPrefix: "NEXT_PUBLIC_",
|
||||
...viteBaseConfig,
|
||||
base: "/embed/",
|
||||
build: {
|
||||
minify: "terser",
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly EMBED_PUBLIC_WEBAPP_URL: string;
|
||||
readonly EMBED_PUBLIC_VERCEL_URL: string;
|
||||
readonly EMBED_PUBLIC_EMBED_LIB_URL: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "@calcom/embed-react",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6-beta.10",
|
||||
"description": "Embed Cal Link as a React Component",
|
||||
"scripts": {
|
||||
"dev": "vite --port=3101 --open",
|
||||
"tsc": "tsc",
|
||||
"build": "vite build && yarn tsc --emitDeclarationOnly --declarationDir dist",
|
||||
"preview": "vite preview",
|
||||
"prepare": "yarn build",
|
||||
"prepare": "NEXT_PUBLIC_EMBED_LIB_URL='https://app.cal.com/embed/embed.js' NEXT_PUBLIC_WEBAPP_URL='https://app.cal.com' yarn build",
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"lint": "eslint --ext .ts,.js,.tsx,.jsx ./src",
|
||||
"embed-tests": "yarn playwright test --config=./playwright/config/playwright.config.ts",
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"main": "./dist/Cal.umd.js",
|
||||
"module": "./dist/Cal.es.js",
|
||||
"types": "./dist/src/index.d.ts",
|
||||
"types": "./dist/index.d.ts",
|
||||
"peerDependencies": {
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0"
|
||||
@@ -32,14 +32,16 @@
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@calcom/embed-snippet": "^1.0.0",
|
||||
"@types/react": "18.0.9",
|
||||
"@types/react-dom": "18.0.4",
|
||||
"@vitejs/plugin-react": "^1.3.2",
|
||||
"eslint": "^8.15.0",
|
||||
"vite": "^2.9.9"
|
||||
"vite": "^2.9.9",
|
||||
"playwright": "^1.22.1",
|
||||
"typescript": "^4.6.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": "^4.6.4"
|
||||
"@calcom/embed-snippet": "1.0.1-beta.10",
|
||||
"@calcom/embed-core": "1.1.0-beta.10"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CalWindow } from "@calcom/embed-snippet";
|
||||
import { CalWindow } from "@calcom/embed-core";
|
||||
|
||||
import Cal from "./Cal";
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
"@lib/*": ["../../../apps/web/lib/*"]
|
||||
}
|
||||
},
|
||||
"include": ["."],
|
||||
"include": ["src","env.d.ts"],
|
||||
"exclude": ["dist", "build", "node_modules", "test-cal.tsx"]
|
||||
}
|
||||
@@ -2,10 +2,12 @@ import react from "@vitejs/plugin-react";
|
||||
import path from "path";
|
||||
import { defineConfig } from "vite";
|
||||
|
||||
import viteBaseConfig from "../vite.config";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
...viteBaseConfig,
|
||||
plugins: [react()],
|
||||
envPrefix: "NEXT_PUBLIC_",
|
||||
build: {
|
||||
lib: {
|
||||
entry: path.resolve(__dirname, "src/index.ts"),
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
{
|
||||
"name": "@calcom/embed-snippet",
|
||||
"version": "1.0.0",
|
||||
"main": "src/index.ts",
|
||||
"version": "1.0.1-beta.10",
|
||||
"main": "./dist/snippet.umd.js",
|
||||
"module": "./dist/snippet.es.js",
|
||||
"description": "Vanilla JS embed snippet that is responsible to fetch @calcom/embed-core and thus show Cal Link as an embed on a page.",
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"build": "vite build && yarn tsc --emitDeclarationOnly --declarationDir dist",
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
"lint": "eslint --ext .ts,.js src"
|
||||
"lint": "eslint --ext .ts,.js src",
|
||||
"prepare":"NEXT_PUBLIC_EMBED_LIB_URL='https://app.cal.com/embed/embed.js' NEXT_PUBLIC_WEBAPP_URL='https://app.cal.com' yarn build"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"types": "./dist/index.d.ts",
|
||||
"devDependencies": {
|
||||
"eslint": "^8.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/embed-core": "^1.1.0-beta.10"
|
||||
}
|
||||
}
|
||||
@@ -4,30 +4,12 @@
|
||||
* As we want to keep control on the size of this snippet but we want some portion of it to be still readable.
|
||||
* So, write the code that you need directly but keep it short.
|
||||
*/
|
||||
import type { Cal as CalClass, InstructionQueue } from "@calcom/embed-core/src/embed";
|
||||
import { CalWindow } from "@calcom/embed-core";
|
||||
|
||||
const WEBAPP_URL =
|
||||
import.meta.env.NEXT_PUBLIC_WEBAPP_URL || `https://${import.meta.env.NEXT_PUBLIC_VERCEL_URL}`;
|
||||
import.meta.env.EMBED_PUBLIC_WEBAPP_URL || `https://${import.meta.env.EMBED_PUBLIC_VERCEL_URL}`;
|
||||
|
||||
const EMBED_LIB_URL = import.meta.env.NEXT_PUBLIC_EMBED_LIB_URL || `${WEBAPP_URL}/embed/embed.js`;
|
||||
|
||||
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?: CalClass;
|
||||
__css?: string;
|
||||
fingerprint?: string;
|
||||
__logQueue?: any[];
|
||||
}
|
||||
|
||||
export interface CalWindow extends Window {
|
||||
Cal?: GlobalCal;
|
||||
}
|
||||
const EMBED_LIB_URL = import.meta.env.EMBED_PUBLIC_EMBED_LIB_URL || `${WEBAPP_URL}/embed/embed.js`;
|
||||
|
||||
export default function EmbedSnippet(url = EMBED_LIB_URL) {
|
||||
(function (C: CalWindow, A, L) {
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
"extends": "@calcom/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"module": "esnext"
|
||||
"module": "esnext",
|
||||
"declaration": true
|
||||
},
|
||||
"include": ["."],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
require("dotenv").config({ path: "../../../.env" });
|
||||
import viteBaseConfig from "../vite.config";
|
||||
|
||||
const path = require("path");
|
||||
const { defineConfig } = require("vite");
|
||||
|
||||
process.env.NEXT_PUBLIC_VERCEL_URL = process.env.VERCEL_URL;
|
||||
|
||||
module.exports = defineConfig({
|
||||
...viteBaseConfig,
|
||||
build: {
|
||||
envPrefix: "NEXT_PUBLIC_",
|
||||
lib: {
|
||||
entry: path.resolve(__dirname, "src", "index.ts"),
|
||||
name: "snippet",
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
require("dotenv").config({ path: "../../.env" });
|
||||
process.env.EMBED_PUBLIC_VERCEL_URL = process.env.VERCEL_URL;
|
||||
process.env.EMBED_PUBLIC_WEBAPP_URL = process.env.NEXT_PUBLIC_WEBAPP_URL;
|
||||
process.env.EMBED_PUBLIC_EMBED_LIB_URL = process.env.NEXT_PUBLIC_EMBED_LIB_URL;
|
||||
|
||||
const viteBaseConfig = {
|
||||
envPrefix: "EMBED_PUBLIC_",
|
||||
};
|
||||
export default viteBaseConfig;
|
||||