mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix tests
This commit is contained in:
parent
e68edb9f73
commit
e3fa2905f2
6 changed files with 51785 additions and 35 deletions
|
@ -28,6 +28,7 @@ import {
|
||||||
FONT_FAMILY,
|
FONT_FAMILY,
|
||||||
ROUNDNESS,
|
ROUNDNESS,
|
||||||
DEFAULT_SIDEBAR,
|
DEFAULT_SIDEBAR,
|
||||||
|
DEFAULT_ELEMENT_PROPS,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { getDefaultAppState } from "../appState";
|
import { getDefaultAppState } from "../appState";
|
||||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||||
|
@ -81,7 +82,7 @@ const getFontFamilyByName = (fontFamilyName: string): FontFamilyValues => {
|
||||||
return DEFAULT_FONT_FAMILY;
|
return DEFAULT_FONT_FAMILY;
|
||||||
};
|
};
|
||||||
|
|
||||||
const restoreElementWithProperties = <
|
export const restoreElementWithProperties = <
|
||||||
T extends Required<Omit<ExcalidrawElement, "customData">> & {
|
T extends Required<Omit<ExcalidrawElement, "customData">> & {
|
||||||
customData?: ExcalidrawElement["customData"];
|
customData?: ExcalidrawElement["customData"];
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
|
@ -112,18 +113,20 @@ const restoreElementWithProperties = <
|
||||||
versionNonce: element.versionNonce ?? 0,
|
versionNonce: element.versionNonce ?? 0,
|
||||||
isDeleted: element.isDeleted ?? false,
|
isDeleted: element.isDeleted ?? false,
|
||||||
id: element.id || randomId(),
|
id: element.id || randomId(),
|
||||||
fillStyle: element.fillStyle || "hachure",
|
fillStyle: element.fillStyle || DEFAULT_ELEMENT_PROPS.fillStyle,
|
||||||
strokeWidth: element.strokeWidth || 1,
|
strokeWidth: element.strokeWidth || DEFAULT_ELEMENT_PROPS.strokeWidth,
|
||||||
strokeStyle: element.strokeStyle ?? "solid",
|
strokeStyle: element.strokeStyle ?? DEFAULT_ELEMENT_PROPS.strokeStyle,
|
||||||
roughness: element.roughness ?? 1,
|
roughness: element.roughness ?? DEFAULT_ELEMENT_PROPS.roughness,
|
||||||
opacity: element.opacity == null ? 100 : element.opacity,
|
opacity:
|
||||||
|
element.opacity == null ? DEFAULT_ELEMENT_PROPS.opacity : element.opacity,
|
||||||
angle: element.angle || 0,
|
angle: element.angle || 0,
|
||||||
x: extra.x ?? element.x ?? 0,
|
x: extra.x ?? element.x ?? 0,
|
||||||
y: extra.y ?? element.y ?? 0,
|
y: extra.y ?? element.y ?? 0,
|
||||||
strokeColor: element.strokeColor || oc.black,
|
strokeColor: element.strokeColor || DEFAULT_ELEMENT_PROPS.strokeColor,
|
||||||
backgroundColor: element.backgroundColor || "transparent",
|
backgroundColor:
|
||||||
width: element.width,
|
element.backgroundColor || DEFAULT_ELEMENT_PROPS.backgroundColor,
|
||||||
height: element.height,
|
width: element.width || 0,
|
||||||
|
height: element.height || 0,
|
||||||
seed: element.seed ?? 1,
|
seed: element.seed ?? 1,
|
||||||
groupIds: element.groupIds ?? [],
|
groupIds: element.groupIds ?? [],
|
||||||
roundness: element.roundness
|
roundness: element.roundness
|
||||||
|
@ -196,7 +199,6 @@ const restoreElement = (
|
||||||
lineHeight,
|
lineHeight,
|
||||||
);
|
);
|
||||||
element = restoreElementWithProperties(element, {
|
element = restoreElementWithProperties(element, {
|
||||||
type: "text",
|
|
||||||
fontSize,
|
fontSize,
|
||||||
fontFamily,
|
fontFamily,
|
||||||
text,
|
text,
|
||||||
|
|
|
@ -49,6 +49,7 @@ import {
|
||||||
import { isArrowElement } from "./typeChecks";
|
import { isArrowElement } from "./typeChecks";
|
||||||
import { MarkOptional, Merge, Mutable } from "../utility-types";
|
import { MarkOptional, Merge, Mutable } from "../utility-types";
|
||||||
import { ImportedDataState } from "../data/types";
|
import { ImportedDataState } from "../data/types";
|
||||||
|
import { restoreElementWithProperties } from "../data/restore";
|
||||||
|
|
||||||
export const ELEMENTS_SUPPORTING_PROGRAMMATIC_API = [
|
export const ELEMENTS_SUPPORTING_PROGRAMMATIC_API = [
|
||||||
"rectangle",
|
"rectangle",
|
||||||
|
@ -103,7 +104,6 @@ const _newElementBase = <T extends ExcalidrawElement>(
|
||||||
...rest
|
...rest
|
||||||
}: ElementConstructorOpts & Omit<Partial<ExcalidrawGenericElement>, "type">,
|
}: ElementConstructorOpts & Omit<Partial<ExcalidrawGenericElement>, "type">,
|
||||||
) => {
|
) => {
|
||||||
console.log("width", width);
|
|
||||||
// assign type to guard against excess properties
|
// assign type to guard against excess properties
|
||||||
const element: Merge<ExcalidrawGenericElement, { type: T["type"] }> = {
|
const element: Merge<ExcalidrawGenericElement, { type: T["type"] }> = {
|
||||||
id: rest.id || randomId(),
|
id: rest.id || randomId(),
|
||||||
|
@ -668,8 +668,7 @@ export const convertToExcalidrawElements = (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)) {
|
if (!ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)) {
|
||||||
//@ts-ignore
|
res.push(element as ExcalidrawElement);
|
||||||
res.push(element);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
@ -681,12 +680,11 @@ export const convertToExcalidrawElements = (
|
||||||
let excalidrawElement;
|
let excalidrawElement;
|
||||||
const { type, ...rest } = element;
|
const { type, ...rest } = element;
|
||||||
if (element.type === "text") {
|
if (element.type === "text") {
|
||||||
//@ts-ignore
|
excalidrawElement = {
|
||||||
excalidrawElement = newTextElement({
|
|
||||||
...element,
|
...element,
|
||||||
});
|
} as ExcalidrawTextElement;
|
||||||
} else if (type === "arrow" || type === "line") {
|
} else if (type === "arrow" || type === "line") {
|
||||||
excalidrawElement = newLinearElement({
|
excalidrawElement = {
|
||||||
type,
|
type,
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 24,
|
height: 24,
|
||||||
|
@ -696,10 +694,9 @@ export const convertToExcalidrawElements = (
|
||||||
[200, 0],
|
[200, 0],
|
||||||
],
|
],
|
||||||
...rest,
|
...rest,
|
||||||
});
|
} as ExcalidrawLinearElement;
|
||||||
} else {
|
} else {
|
||||||
//@ts-ignore
|
excalidrawElement = {
|
||||||
excalidrawElement = newElement({
|
|
||||||
...element,
|
...element,
|
||||||
width:
|
width:
|
||||||
element?.width ||
|
element?.width ||
|
||||||
|
@ -711,9 +708,8 @@ export const convertToExcalidrawElements = (
|
||||||
(ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)
|
(ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)
|
||||||
? 100
|
? 100
|
||||||
: 0),
|
: 0),
|
||||||
});
|
} as ExcalidrawGenericElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.push(excalidrawElement);
|
res.push(excalidrawElement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -91,7 +91,6 @@ export const redrawTextBoundingBox = (
|
||||||
textElement as ExcalidrawTextElementWithContainer,
|
textElement as ExcalidrawTextElementWithContainer,
|
||||||
);
|
);
|
||||||
const maxContainerWidth = getBoundTextMaxWidth(container);
|
const maxContainerWidth = getBoundTextMaxWidth(container);
|
||||||
console.log(metrics, maxContainerWidth, container);
|
|
||||||
if (metrics.height > maxContainerHeight) {
|
if (metrics.height > maxContainerHeight) {
|
||||||
const nextHeight = computeContainerDimensionForBoundText(
|
const nextHeight = computeContainerDimensionForBoundText(
|
||||||
metrics.height,
|
metrics.height,
|
||||||
|
|
|
@ -187,28 +187,17 @@ export default function App({ appTitle, useCustom, customArgs }: AppProps) {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: "rectangle",
|
type: "rectangle",
|
||||||
version: 141,
|
|
||||||
versionNonce: 361174001,
|
|
||||||
isDeleted: false,
|
|
||||||
id: "oDVXy8D6rom3H1-LLH2-f",
|
|
||||||
fillStyle: "hachure",
|
fillStyle: "hachure",
|
||||||
strokeWidth: 1,
|
strokeWidth: 1,
|
||||||
strokeStyle: "solid",
|
strokeStyle: "solid",
|
||||||
roughness: 1,
|
roughness: 1,
|
||||||
opacity: 100,
|
|
||||||
angle: 0,
|
angle: 0,
|
||||||
x: 100.50390625,
|
x: 100.50390625,
|
||||||
y: 93.67578125,
|
y: 93.67578125,
|
||||||
strokeColor: "#c92a2a",
|
strokeColor: "#c92a2a",
|
||||||
backgroundColor: "transparent",
|
|
||||||
width: 186.47265625,
|
width: 186.47265625,
|
||||||
height: 141.9765625,
|
height: 141.9765625,
|
||||||
seed: 1968410350,
|
seed: 1968410350,
|
||||||
groupIds: [],
|
|
||||||
boundElements: null,
|
|
||||||
locked: false,
|
|
||||||
link: null,
|
|
||||||
updated: 1,
|
|
||||||
roundness: {
|
roundness: {
|
||||||
type: ROUNDNESS.ADAPTIVE_RADIUS,
|
type: ROUNDNESS.ADAPTIVE_RADIUS,
|
||||||
value: 32,
|
value: 32,
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue