mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Rewrite restore to guard against missing migrations (#1664)
This commit is contained in:
parent
56f8bc092d
commit
44a88d2d58
5 changed files with 131 additions and 117 deletions
|
@ -45,7 +45,7 @@ export {
|
|||
getPerfectElementSize,
|
||||
isInvisiblySmallElement,
|
||||
resizePerfectLineForNWHandler,
|
||||
normalizeDimensions,
|
||||
getNormalizedDimensions,
|
||||
} from "./sizeHelpers";
|
||||
export { showSelectedShapeActions } from "./showSelectedShapeActions";
|
||||
|
||||
|
|
|
@ -81,31 +81,32 @@ export const resizePerfectLineForNWHandler = (
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {boolean} whether element was normalized
|
||||
*/
|
||||
export const normalizeDimensions = (
|
||||
element: ExcalidrawElement | null,
|
||||
): element is ExcalidrawElement => {
|
||||
if (!element || (element.width >= 0 && element.height >= 0)) {
|
||||
return false;
|
||||
}
|
||||
export const getNormalizedDimensions = (
|
||||
element: Pick<ExcalidrawElement, "width" | "height" | "x" | "y">,
|
||||
): {
|
||||
width: ExcalidrawElement["width"];
|
||||
height: ExcalidrawElement["height"];
|
||||
x: ExcalidrawElement["x"];
|
||||
y: ExcalidrawElement["y"];
|
||||
} => {
|
||||
const ret = {
|
||||
width: element.width,
|
||||
height: element.height,
|
||||
x: element.x,
|
||||
y: element.y,
|
||||
};
|
||||
|
||||
if (element.width < 0) {
|
||||
const nextWidth = Math.abs(element.width);
|
||||
mutateElement(element, {
|
||||
width: nextWidth,
|
||||
x: element.x - nextWidth,
|
||||
});
|
||||
ret.width = nextWidth;
|
||||
ret.x = element.x - nextWidth;
|
||||
}
|
||||
|
||||
if (element.height < 0) {
|
||||
const nextHeight = Math.abs(element.height);
|
||||
mutateElement(element, {
|
||||
height: nextHeight,
|
||||
y: element.y - nextHeight,
|
||||
});
|
||||
ret.height = nextHeight;
|
||||
ret.y = element.y - nextHeight;
|
||||
}
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
};
|
||||
|
|
|
@ -24,12 +24,17 @@ type _ExcalidrawElementBase = Readonly<{
|
|||
groupIds: GroupId[];
|
||||
}>;
|
||||
|
||||
export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {
|
||||
type: "selection";
|
||||
};
|
||||
/**
|
||||
* These are elements that don't have any additional properties.
|
||||
*/
|
||||
export type ExcalidrawGenericElement = _ExcalidrawElementBase & {
|
||||
type: "selection" | "rectangle" | "diamond" | "ellipse";
|
||||
};
|
||||
export type ExcalidrawGenericElement =
|
||||
| ExcalidrawSelectionElement
|
||||
| (_ExcalidrawElementBase & {
|
||||
type: "rectangle" | "diamond" | "ellipse";
|
||||
});
|
||||
|
||||
/**
|
||||
* ExcalidrawElement should be JSON serializable and (eventually) contain
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue