mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
preserve bindings if present and fix testcases
This commit is contained in:
parent
75cfe54b15
commit
f113a393e6
4 changed files with 23 additions and 10 deletions
|
@ -154,7 +154,6 @@ export const restoreElementWithProperties = <
|
||||||
if (PRECEDING_ELEMENT_KEY in element) {
|
if (PRECEDING_ELEMENT_KEY in element) {
|
||||||
base[PRECEDING_ELEMENT_KEY] = element[PRECEDING_ELEMENT_KEY];
|
base[PRECEDING_ELEMENT_KEY] = element[PRECEDING_ELEMENT_KEY];
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...base,
|
...base,
|
||||||
...getNormalizedDimensions(base),
|
...getNormalizedDimensions(base),
|
||||||
|
@ -237,7 +236,6 @@ const restoreElement = (
|
||||||
startArrowhead = null,
|
startArrowhead = null,
|
||||||
endArrowhead = element.type === "arrow" ? "arrow" : null,
|
endArrowhead = element.type === "arrow" ? "arrow" : null,
|
||||||
} = element;
|
} = element;
|
||||||
|
|
||||||
let x = element.x;
|
let x = element.x;
|
||||||
let y = element.y;
|
let y = element.y;
|
||||||
let points = // migrate old arrow model to new one
|
let points = // migrate old arrow model to new one
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
Arrowhead,
|
||||||
ExcalidrawBindableElement,
|
ExcalidrawBindableElement,
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
FontFamilyValues,
|
FontFamilyValues,
|
||||||
|
@ -89,6 +90,7 @@ export interface ImportedDataState {
|
||||||
end?: {
|
end?: {
|
||||||
type: ExcalidrawBindableElement["type"];
|
type: ExcalidrawBindableElement["type"];
|
||||||
} & MarkOptional<ElementConstructorOpts, "x" | "y">;
|
} & MarkOptional<ElementConstructorOpts, "x" | "y">;
|
||||||
|
endArrowhead?: Arrowhead | null;
|
||||||
} & ElementConstructorOpts)
|
} & ElementConstructorOpts)
|
||||||
)[]
|
)[]
|
||||||
| null;
|
| null;
|
||||||
|
|
|
@ -733,10 +733,18 @@ export const convertToExcalidrawElements = (
|
||||||
} as ExcalidrawTextElement;
|
} as ExcalidrawTextElement;
|
||||||
res.push(excalidrawElement);
|
res.push(excalidrawElement);
|
||||||
} else if (element.type === "arrow" || element.type === "line") {
|
} else if (element.type === "arrow" || element.type === "line") {
|
||||||
//@ts-ignore
|
const {
|
||||||
const { start, end, type, endArrowHead, ...rest } = element;
|
//@ts-ignore
|
||||||
|
start,
|
||||||
|
//@ts-ignore
|
||||||
|
end,
|
||||||
|
type,
|
||||||
|
//@ts-ignore
|
||||||
|
endArrowhead = element.type === "arrow" ? "arrow" : null,
|
||||||
|
...rest
|
||||||
|
} = element;
|
||||||
|
|
||||||
excalidrawElement = {
|
excalidrawElement = newLinearElement({
|
||||||
type,
|
type,
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 24,
|
height: 24,
|
||||||
|
@ -744,10 +752,16 @@ export const convertToExcalidrawElements = (
|
||||||
[0, 0],
|
[0, 0],
|
||||||
[200, 0],
|
[200, 0],
|
||||||
],
|
],
|
||||||
endArrowhead: endArrowHead || type === "arrow" ? "arrow" : null,
|
endArrowhead,
|
||||||
...rest,
|
...rest,
|
||||||
} as ExcalidrawLinearElement;
|
});
|
||||||
|
|
||||||
|
mutateElement(excalidrawElement, {
|
||||||
|
//@ts-ignore
|
||||||
|
startBinding: element?.startBinding || null,
|
||||||
|
//@ts-ignore
|
||||||
|
endBinding: element.endBinding || null,
|
||||||
|
});
|
||||||
let startBoundElement;
|
let startBoundElement;
|
||||||
let endBoundElement;
|
let endBoundElement;
|
||||||
if (start) {
|
if (start) {
|
||||||
|
|
|
@ -139,9 +139,8 @@ describe("restoreElements", () => {
|
||||||
expect(restoredArrow).toMatchSnapshot({ seed: expect.any(Number) });
|
expect(restoredArrow).toMatchSnapshot({ seed: expect.any(Number) });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when arrow element has defined endArrowHead", () => {
|
it('should set arrow element endArrowHead as "arrow" when arrow element endArrowHead is null', () => {
|
||||||
const arrowElement = API.createElement({ type: "arrow" });
|
const arrowElement = API.createElement({ type: "arrow" });
|
||||||
|
|
||||||
const restoredElements = restore.restoreElements([arrowElement], null);
|
const restoredElements = restore.restoreElements([arrowElement], null);
|
||||||
|
|
||||||
const restoredArrow = restoredElements[0] as ExcalidrawLinearElement;
|
const restoredArrow = restoredElements[0] as ExcalidrawLinearElement;
|
||||||
|
@ -149,7 +148,7 @@ describe("restoreElements", () => {
|
||||||
expect(arrowElement.endArrowhead).toBe(restoredArrow.endArrowhead);
|
expect(arrowElement.endArrowhead).toBe(restoredArrow.endArrowhead);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("when arrow element has undefined endArrowHead", () => {
|
it('should set arrow element endArrowHead as "arrow" when arrow element endArrowHead is undefined', () => {
|
||||||
const arrowElement = API.createElement({ type: "arrow" });
|
const arrowElement = API.createElement({ type: "arrow" });
|
||||||
Object.defineProperty(arrowElement, "endArrowhead", {
|
Object.defineProperty(arrowElement, "endArrowhead", {
|
||||||
get: jest.fn(() => undefined),
|
get: jest.fn(() => undefined),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue