mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
refactor: decoupling global Scene state part-1 (#7577)
This commit is contained in:
parent
740a165452
commit
0415c616b1
31 changed files with 630 additions and 384 deletions
|
@ -40,6 +40,7 @@ import { arrayToMap } from "../utils";
|
|||
import { MarkOptional, Mutable } from "../utility-types";
|
||||
import {
|
||||
detectLineHeight,
|
||||
getContainerElement,
|
||||
getDefaultLineHeight,
|
||||
measureBaseline,
|
||||
} from "../element/textElement";
|
||||
|
@ -179,7 +180,6 @@ const restoreElementWithProperties = <
|
|||
|
||||
const restoreElement = (
|
||||
element: Exclude<ExcalidrawElement, ExcalidrawSelectionElement>,
|
||||
refreshDimensions = false,
|
||||
): typeof element | null => {
|
||||
switch (element.type) {
|
||||
case "text":
|
||||
|
@ -232,10 +232,6 @@ const restoreElement = (
|
|||
element = bumpVersion(element);
|
||||
}
|
||||
|
||||
if (refreshDimensions) {
|
||||
element = { ...element, ...refreshTextDimensions(element) };
|
||||
}
|
||||
|
||||
return element;
|
||||
case "freedraw": {
|
||||
return restoreElementWithProperties(element, {
|
||||
|
@ -426,10 +422,7 @@ export const restoreElements = (
|
|||
// filtering out selection, which is legacy, no longer kept in elements,
|
||||
// and causing issues if retained
|
||||
if (element.type !== "selection" && !isInvisiblySmallElement(element)) {
|
||||
let migratedElement: ExcalidrawElement | null = restoreElement(
|
||||
element,
|
||||
opts?.refreshDimensions,
|
||||
);
|
||||
let migratedElement: ExcalidrawElement | null = restoreElement(element);
|
||||
if (migratedElement) {
|
||||
const localElement = localElementsMap?.get(element.id);
|
||||
if (localElement && localElement.version > migratedElement.version) {
|
||||
|
@ -462,6 +455,16 @@ export const restoreElements = (
|
|||
} else if (element.boundElements) {
|
||||
repairContainerElement(element, restoredElementsMap);
|
||||
}
|
||||
|
||||
if (opts.refreshDimensions && isTextElement(element)) {
|
||||
Object.assign(
|
||||
element,
|
||||
refreshTextDimensions(
|
||||
element,
|
||||
getContainerElement(element, restoredElementsMap),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return restoredElements;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue