mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
remove more ts ignore
This commit is contained in:
parent
f57e72443d
commit
03131750be
1 changed files with 25 additions and 26 deletions
|
@ -17,7 +17,6 @@ import {
|
||||||
regenerateId,
|
regenerateId,
|
||||||
} from "../element/newElement";
|
} from "../element/newElement";
|
||||||
import {
|
import {
|
||||||
VALID_CONTAINER_TYPES,
|
|
||||||
getDefaultLineHeight,
|
getDefaultLineHeight,
|
||||||
measureText,
|
measureText,
|
||||||
normalizeText,
|
normalizeText,
|
||||||
|
@ -42,14 +41,21 @@ export const ELEMENTS_SUPPORTING_PROGRAMMATIC_API = [
|
||||||
"line",
|
"line",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const DEFAULT_LINEAR_ELEMENT_PROPS = {
|
||||||
|
width: 300,
|
||||||
|
height: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const DEFAULT_DIMENSION = 100;
|
||||||
|
|
||||||
const bindTextToContainer = (
|
const bindTextToContainer = (
|
||||||
containerProps: ValidContainer | ValidLinearElement,
|
containerProps: ValidContainer | ValidLinearElement,
|
||||||
textProps: { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
|
textProps: { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
|
||||||
) => {
|
) => {
|
||||||
let container;
|
let container;
|
||||||
if (containerProps.type === "arrow") {
|
if (containerProps.type === "arrow") {
|
||||||
const width = containerProps.width || 300;
|
const width = containerProps.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
||||||
const height = containerProps.height || 0;
|
const height = containerProps.height || DEFAULT_LINEAR_ELEMENT_PROPS.height;
|
||||||
container = newLinearElement({
|
container = newLinearElement({
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
@ -102,8 +108,8 @@ const bindLinearElementToElement = (
|
||||||
endArrowhead = linearElement.type === "arrow" ? "arrow" : null,
|
endArrowhead = linearElement.type === "arrow" ? "arrow" : null,
|
||||||
...rest
|
...rest
|
||||||
} = linearElement;
|
} = linearElement;
|
||||||
const width = linearElement.width || 300;
|
const width = linearElement.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
||||||
const height = linearElement.height || 0;
|
const height = linearElement.height || DEFAULT_LINEAR_ELEMENT_PROPS.height;
|
||||||
const excliadrawLinearElement = newLinearElement({
|
const excliadrawLinearElement = newLinearElement({
|
||||||
type,
|
type,
|
||||||
width,
|
width,
|
||||||
|
@ -125,8 +131,8 @@ const bindLinearElementToElement = (
|
||||||
});
|
});
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
const width = start?.width ?? 100;
|
const width = start?.width ?? DEFAULT_DIMENSION;
|
||||||
const height = start?.height ?? 100;
|
const height = start?.height ?? DEFAULT_DIMENSION;
|
||||||
const existingElement = start.id
|
const existingElement = start.id
|
||||||
? excalidrawElements.get().find((ele) => ele?.id === start.id)
|
? excalidrawElements.get().find((ele) => ele?.id === start.id)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
@ -163,8 +169,8 @@ const bindLinearElementToElement = (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (end) {
|
if (end) {
|
||||||
const height = end?.height ?? 100;
|
const height = end?.height ?? DEFAULT_DIMENSION;
|
||||||
const width = end?.width ?? 100;
|
const width = end?.width ?? DEFAULT_DIMENSION;
|
||||||
|
|
||||||
const existingElement = end.id
|
const existingElement = end.id
|
||||||
? excalidrawElements.get().find((ele) => ele?.id === end.id)
|
? excalidrawElements.get().find((ele) => ele?.id === end.id)
|
||||||
|
@ -270,15 +276,15 @@ export const convertToExcalidrawElements = (
|
||||||
const elementWithid = { ...element, id: elementId };
|
const elementWithid = { ...element, id: elementId };
|
||||||
|
|
||||||
if (
|
if (
|
||||||
VALID_CONTAINER_TYPES.has(elementWithid.type) &&
|
(elementWithid.type === "rectangle" ||
|
||||||
//@ts-ignore
|
elementWithid.type === "ellipse" ||
|
||||||
|
elementWithid.type === "diamond" ||
|
||||||
|
elementWithid.type === "arrow") &&
|
||||||
elementWithid?.label?.text
|
elementWithid?.label?.text
|
||||||
) {
|
) {
|
||||||
let [container, text] = bindTextToContainer(
|
let [container, text] = bindTextToContainer(
|
||||||
//@ts-ignore
|
|
||||||
elementWithid,
|
elementWithid,
|
||||||
//@ts-ignore
|
elementWithid?.label,
|
||||||
elementWithid.label,
|
|
||||||
);
|
);
|
||||||
excalidrawElements.push(container);
|
excalidrawElements.push(container);
|
||||||
excalidrawElements.push(text);
|
excalidrawElements.push(text);
|
||||||
|
@ -334,8 +340,9 @@ export const convertToExcalidrawElements = (
|
||||||
excalidrawElements.push(endBoundElement);
|
excalidrawElements.push(endBoundElement);
|
||||||
}
|
}
|
||||||
} else if (elementWithid.type === "line") {
|
} else if (elementWithid.type === "line") {
|
||||||
const width = elementWithid.width || 300;
|
const width = elementWithid.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
||||||
const height = elementWithid.height || 0;
|
const height =
|
||||||
|
elementWithid.height || DEFAULT_LINEAR_ELEMENT_PROPS.height;
|
||||||
const lineElement = newLinearElement({
|
const lineElement = newLinearElement({
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
@ -349,16 +356,8 @@ export const convertToExcalidrawElements = (
|
||||||
} else {
|
} else {
|
||||||
excalidrawElement = {
|
excalidrawElement = {
|
||||||
...elementWithid,
|
...elementWithid,
|
||||||
width:
|
width: elementWithid?.width || DEFAULT_DIMENSION,
|
||||||
elementWithid?.width ||
|
height: elementWithid?.height || DEFAULT_DIMENSION,
|
||||||
(ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(elementWithid.type)
|
|
||||||
? 100
|
|
||||||
: 0),
|
|
||||||
height:
|
|
||||||
elementWithid?.height ||
|
|
||||||
(ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(elementWithid.type)
|
|
||||||
? 100
|
|
||||||
: 0),
|
|
||||||
} as ExcalidrawGenericElement;
|
} as ExcalidrawGenericElement;
|
||||||
excalidrawElements.push(excalidrawElement);
|
excalidrawElements.push(excalidrawElement);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue