|
@@ -14,9 +14,7 @@ import {
|
|
UnsubscribeCallback,
|
|
UnsubscribeCallback,
|
|
Zoom,
|
|
Zoom,
|
|
} from "./types";
|
|
} from "./types";
|
|
-import { unstable_batchedUpdates } from "react-dom";
|
|
|
|
import { ResolutionType } from "./utility-types";
|
|
import { ResolutionType } from "./utility-types";
|
|
-import React from "react";
|
|
|
|
|
|
|
|
let mockDateTime: string | null = null;
|
|
let mockDateTime: string | null = null;
|
|
|
|
|
|
@@ -555,33 +553,6 @@ export const resolvablePromise = <T>() => {
|
|
return promise as ResolvablePromise<T>;
|
|
return promise as ResolvablePromise<T>;
|
|
};
|
|
};
|
|
|
|
|
|
-/**
|
|
|
|
- * @param func handler taking at most single parameter (event).
|
|
|
|
- */
|
|
|
|
-export const withBatchedUpdates = <
|
|
|
|
- TFunction extends ((event: any) => void) | (() => void),
|
|
|
|
->(
|
|
|
|
- func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never,
|
|
|
|
-) =>
|
|
|
|
- ((event) => {
|
|
|
|
- unstable_batchedUpdates(func as TFunction, event);
|
|
|
|
- }) as TFunction;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * barches React state updates and throttles the calls to a single call per
|
|
|
|
- * animation frame
|
|
|
|
- */
|
|
|
|
-export const withBatchedUpdatesThrottled = <
|
|
|
|
- TFunction extends ((event: any) => void) | (() => void),
|
|
|
|
->(
|
|
|
|
- func: Parameters<TFunction>["length"] extends 0 | 1 ? TFunction : never,
|
|
|
|
-) => {
|
|
|
|
- // @ts-ignore
|
|
|
|
- return throttleRAF<Parameters<TFunction>>(((event) => {
|
|
|
|
- unstable_batchedUpdates(func, event);
|
|
|
|
- }) as TFunction);
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
//https://stackoverflow.com/a/9462382/8418
|
|
//https://stackoverflow.com/a/9462382/8418
|
|
export const nFormatter = (num: number, digits: number): string => {
|
|
export const nFormatter = (num: number, digits: number): string => {
|
|
const si = [
|
|
const si = [
|
|
@@ -939,36 +910,6 @@ export const memoize = <T extends Record<string, any>, R extends any>(
|
|
return ret as typeof func & { clear: () => void };
|
|
return ret as typeof func & { clear: () => void };
|
|
};
|
|
};
|
|
|
|
|
|
-export const isRenderThrottlingEnabled = (() => {
|
|
|
|
- // we don't want to throttle in react < 18 because of #5439 and it was
|
|
|
|
- // getting more complex to maintain the fix
|
|
|
|
- let IS_REACT_18_AND_UP: boolean;
|
|
|
|
- try {
|
|
|
|
- const version = React.version.split(".");
|
|
|
|
- IS_REACT_18_AND_UP = Number(version[0]) > 17;
|
|
|
|
- } catch {
|
|
|
|
- IS_REACT_18_AND_UP = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let hasWarned = false;
|
|
|
|
-
|
|
|
|
- return () => {
|
|
|
|
- if (window.EXCALIDRAW_THROTTLE_RENDER === true) {
|
|
|
|
- if (!IS_REACT_18_AND_UP) {
|
|
|
|
- if (!hasWarned) {
|
|
|
|
- hasWarned = true;
|
|
|
|
- console.warn(
|
|
|
|
- "Excalidraw: render throttling is disabled on React versions < 18.",
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- };
|
|
|
|
-})();
|
|
|
|
-
|
|
|
|
/** Checks if value is inside given collection. Useful for type-safety. */
|
|
/** Checks if value is inside given collection. Useful for type-safety. */
|
|
export const isMemberOf = <T extends string>(
|
|
export const isMemberOf = <T extends string>(
|
|
/** Set/Map/Array/Object */
|
|
/** Set/Map/Array/Object */
|