feat(packages/excalidraw): export throttleRAF (#10912)

This commit is contained in:
David Luzar
2026-03-07 12:05:33 +01:00
committed by GitHub
parent 3d8c12fba4
commit fa1f7d9f22
6 changed files with 123 additions and 5 deletions
+4 -1
View File
@@ -28,7 +28,9 @@ const { h } = window;
const mouse = new Pointer("mouse");
vi.mock("@excalidraw/common", async (importOriginal) => {
const module: any = await importOriginal();
const module = await importOriginal<typeof import("@excalidraw/common")>();
const { mockThrottleRAF } = await import("./helpers/mocks");
return {
__esmodule: true,
...module,
@@ -37,6 +39,7 @@ vi.mock("@excalidraw/common", async (importOriginal) => {
...module.KEYS,
CTRL_OR_CMD: "ctrlKey",
},
throttleRAF: mockThrottleRAF,
};
});
@@ -3,6 +3,25 @@ import React from "react";
import { vi } from "vitest";
import type { parseMermaidToExcalidraw } from "@excalidraw/mermaid-to-excalidraw";
import type { throttleRAF as throttleRAFType } from "@excalidraw/common";
type ThrottledFn<T extends unknown[]> = ((...args: T) => void) & {
flush: () => void;
cancel: () => void;
};
export const mockThrottleRAF: typeof throttleRAFType = <T extends unknown[]>(
fn: (...args: T) => void,
) => {
const ret = ((...args: T) => {
fn(...args);
}) as ThrottledFn<T>;
ret.flush = () => {};
ret.cancel = () => {};
return ret;
};
export const mockMermaidToExcalidraw = (opts: {
parseMermaidToExcalidraw: typeof parseMermaidToExcalidraw;