feat(packages/excalidraw): export throttleRAF (#10912)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user