mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-04-14 16:40:58 -04:00
fix: decouple container cache logic to containerCache. (#7637)
This commit is contained in:
parent
63b50b3586
commit
1741c234a6
5 changed files with 42 additions and 37 deletions
|
@ -17,7 +17,7 @@ import {
|
||||||
getOriginalContainerHeightFromCache,
|
getOriginalContainerHeightFromCache,
|
||||||
resetOriginalContainerCache,
|
resetOriginalContainerCache,
|
||||||
updateOriginalContainerCache,
|
updateOriginalContainerCache,
|
||||||
} from "../element/textWysiwyg";
|
} from "../element/containerCache";
|
||||||
import {
|
import {
|
||||||
hasBoundTextElement,
|
hasBoundTextElement,
|
||||||
isTextBindableContainer,
|
isTextBindableContainer,
|
||||||
|
|
33
packages/excalidraw/element/containerCache.ts
Normal file
33
packages/excalidraw/element/containerCache.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { ExcalidrawTextContainer } from "./types";
|
||||||
|
|
||||||
|
export const originalContainerCache: {
|
||||||
|
[id: ExcalidrawTextContainer["id"]]:
|
||||||
|
| {
|
||||||
|
height: ExcalidrawTextContainer["height"];
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
} = {};
|
||||||
|
|
||||||
|
export const updateOriginalContainerCache = (
|
||||||
|
id: ExcalidrawTextContainer["id"],
|
||||||
|
height: ExcalidrawTextContainer["height"],
|
||||||
|
) => {
|
||||||
|
const data =
|
||||||
|
originalContainerCache[id] || (originalContainerCache[id] = { height });
|
||||||
|
data.height = height;
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetOriginalContainerCache = (
|
||||||
|
id: ExcalidrawTextContainer["id"],
|
||||||
|
) => {
|
||||||
|
if (originalContainerCache[id]) {
|
||||||
|
delete originalContainerCache[id];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getOriginalContainerHeightFromCache = (
|
||||||
|
id: ExcalidrawTextContainer["id"],
|
||||||
|
) => {
|
||||||
|
return originalContainerCache[id]?.height ?? null;
|
||||||
|
};
|
|
@ -31,11 +31,12 @@ import { isTextBindableContainer } from "./typeChecks";
|
||||||
import { getElementAbsoluteCoords } from ".";
|
import { getElementAbsoluteCoords } from ".";
|
||||||
import { getSelectedElements } from "../scene";
|
import { getSelectedElements } from "../scene";
|
||||||
import { isHittingElementNotConsideringBoundingBox } from "./collision";
|
import { isHittingElementNotConsideringBoundingBox } from "./collision";
|
||||||
|
|
||||||
|
import { ExtractSetType } from "../utility-types";
|
||||||
import {
|
import {
|
||||||
resetOriginalContainerCache,
|
resetOriginalContainerCache,
|
||||||
updateOriginalContainerCache,
|
updateOriginalContainerCache,
|
||||||
} from "./textWysiwyg";
|
} from "./containerCache";
|
||||||
import { ExtractSetType } from "../utility-types";
|
|
||||||
|
|
||||||
export const normalizeText = (text: string) => {
|
export const normalizeText = (text: string) => {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { API } from "../tests/helpers/api";
|
import { API } from "../tests/helpers/api";
|
||||||
import { mutateElement } from "./mutateElement";
|
import { mutateElement } from "./mutateElement";
|
||||||
import { getOriginalContainerHeightFromCache } from "./textWysiwyg";
|
import { getOriginalContainerHeightFromCache } from "./containerCache";
|
||||||
import { getTextEditor, updateTextEditor } from "../tests/queries/dom";
|
import { getTextEditor, updateTextEditor } from "../tests/queries/dom";
|
||||||
|
|
||||||
// Unmount ReactDOM from root
|
// Unmount ReactDOM from root
|
||||||
|
|
|
@ -17,7 +17,6 @@ import {
|
||||||
ExcalidrawLinearElement,
|
ExcalidrawLinearElement,
|
||||||
ExcalidrawTextElementWithContainer,
|
ExcalidrawTextElementWithContainer,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
ExcalidrawTextContainer,
|
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { bumpVersion, mutateElement } from "./mutateElement";
|
import { bumpVersion, mutateElement } from "./mutateElement";
|
||||||
|
@ -44,6 +43,10 @@ import { actionZoomIn, actionZoomOut } from "../actions/actionCanvas";
|
||||||
import App from "../components/App";
|
import App from "../components/App";
|
||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import { parseClipboard } from "../clipboard";
|
import { parseClipboard } from "../clipboard";
|
||||||
|
import {
|
||||||
|
originalContainerCache,
|
||||||
|
updateOriginalContainerCache,
|
||||||
|
} from "./containerCache";
|
||||||
|
|
||||||
const getTransform = (
|
const getTransform = (
|
||||||
width: number,
|
width: number,
|
||||||
|
@ -66,38 +69,6 @@ const getTransform = (
|
||||||
return `translate(${translateX}px, ${translateY}px) scale(${zoom.value}) rotate(${degree}deg)`;
|
return `translate(${translateX}px, ${translateY}px) scale(${zoom.value}) rotate(${degree}deg)`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const originalContainerCache: {
|
|
||||||
[id: ExcalidrawTextContainer["id"]]:
|
|
||||||
| {
|
|
||||||
height: ExcalidrawTextContainer["height"];
|
|
||||||
}
|
|
||||||
| undefined;
|
|
||||||
} = {};
|
|
||||||
|
|
||||||
export const updateOriginalContainerCache = (
|
|
||||||
id: ExcalidrawTextContainer["id"],
|
|
||||||
height: ExcalidrawTextContainer["height"],
|
|
||||||
) => {
|
|
||||||
const data =
|
|
||||||
originalContainerCache[id] || (originalContainerCache[id] = { height });
|
|
||||||
data.height = height;
|
|
||||||
return data;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const resetOriginalContainerCache = (
|
|
||||||
id: ExcalidrawTextContainer["id"],
|
|
||||||
) => {
|
|
||||||
if (originalContainerCache[id]) {
|
|
||||||
delete originalContainerCache[id];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getOriginalContainerHeightFromCache = (
|
|
||||||
id: ExcalidrawTextContainer["id"],
|
|
||||||
) => {
|
|
||||||
return originalContainerCache[id]?.height ?? null;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const textWysiwyg = ({
|
export const textWysiwyg = ({
|
||||||
id,
|
id,
|
||||||
onChange,
|
onChange,
|
||||||
|
|
Loading…
Add table
Reference in a new issue