mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
tweak
This commit is contained in:
parent
9e6751c5fb
commit
c1a61b06df
1 changed files with 27 additions and 14 deletions
|
@ -133,6 +133,7 @@ const bindLinearElementToElement = (
|
||||||
if (start) {
|
if (start) {
|
||||||
const width = start?.width ?? DEFAULT_DIMENSION;
|
const width = start?.width ?? DEFAULT_DIMENSION;
|
||||||
const height = start?.height ?? DEFAULT_DIMENSION;
|
const height = start?.height ?? DEFAULT_DIMENSION;
|
||||||
|
|
||||||
let existingElement;
|
let existingElement;
|
||||||
if (start.id) {
|
if (start.id) {
|
||||||
existingElement = excalidrawElements
|
existingElement = excalidrawElements
|
||||||
|
@ -158,6 +159,11 @@ const bindLinearElementToElement = (
|
||||||
} else if (start.type === "text") {
|
} else if (start.type === "text") {
|
||||||
text = start.text;
|
text = start.text;
|
||||||
}
|
}
|
||||||
|
if (!text) {
|
||||||
|
console.error(
|
||||||
|
`No text found for start binding text element for ${excliadrawLinearElement.id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
startBoundElement = newTextElement({
|
startBoundElement = newTextElement({
|
||||||
x: startX,
|
x: startX,
|
||||||
y: startY,
|
y: startY,
|
||||||
|
@ -220,6 +226,12 @@ const bindLinearElementToElement = (
|
||||||
} else if (end.type === "text") {
|
} else if (end.type === "text") {
|
||||||
text = end.text;
|
text = end.text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!text) {
|
||||||
|
console.error(
|
||||||
|
`No text found for end binding text element for ${excliadrawLinearElement.id}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
endBoundElement = newTextElement({
|
endBoundElement = newTextElement({
|
||||||
x: endX,
|
x: endX,
|
||||||
y: endY,
|
y: endY,
|
||||||
|
@ -262,7 +274,7 @@ const excalidrawElements = (() => {
|
||||||
const res: ExcalidrawElement[] = [];
|
const res: ExcalidrawElement[] = [];
|
||||||
const elementMap = new Map<string, number>();
|
const elementMap = new Map<string, number>();
|
||||||
|
|
||||||
const push = (ele?: ExcalidrawElement) => {
|
const add = (ele?: ExcalidrawElement) => {
|
||||||
if (!ele) {
|
if (!ele) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +299,7 @@ const excalidrawElements = (() => {
|
||||||
return index !== undefined && index >= 0;
|
return index !== undefined && index >= 0;
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
push,
|
add,
|
||||||
clear,
|
clear,
|
||||||
get,
|
get,
|
||||||
hasElementWithId,
|
hasElementWithId,
|
||||||
|
@ -310,7 +322,7 @@ export const convertToExcalidrawElements = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)) {
|
if (!ELEMENTS_SUPPORTING_PROGRAMMATIC_API.includes(element.type)) {
|
||||||
excalidrawElements.push(element as ExcalidrawElement);
|
excalidrawElements.add(element as ExcalidrawElement);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -331,8 +343,9 @@ export const convertToExcalidrawElements = (
|
||||||
} & ValidLinearElement),
|
} & ValidLinearElement),
|
||||||
elementWithid?.label,
|
elementWithid?.label,
|
||||||
);
|
);
|
||||||
excalidrawElements.push(container);
|
excalidrawElements.add(container);
|
||||||
excalidrawElements.push(text);
|
excalidrawElements.add(text);
|
||||||
|
|
||||||
if (container.type === "arrow") {
|
if (container.type === "arrow") {
|
||||||
const originalStart =
|
const originalStart =
|
||||||
elementWithid.type === "arrow" ? elementWithid?.start : undefined;
|
elementWithid.type === "arrow" ? elementWithid?.start : undefined;
|
||||||
|
@ -345,9 +358,9 @@ export const convertToExcalidrawElements = (
|
||||||
end: originalEnd,
|
end: originalEnd,
|
||||||
});
|
});
|
||||||
container = linearElement;
|
container = linearElement;
|
||||||
excalidrawElements.push(linearElement);
|
excalidrawElements.add(linearElement);
|
||||||
excalidrawElements.push(startBoundElement);
|
excalidrawElements.add(startBoundElement);
|
||||||
excalidrawElements.push(endBoundElement);
|
excalidrawElements.add(endBoundElement);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let excalidrawElement;
|
let excalidrawElement;
|
||||||
|
@ -371,13 +384,13 @@ export const convertToExcalidrawElements = (
|
||||||
...elementWithid,
|
...elementWithid,
|
||||||
};
|
};
|
||||||
|
|
||||||
excalidrawElements.push(excalidrawElement as ExcalidrawTextElement);
|
excalidrawElements.add(excalidrawElement as ExcalidrawTextElement);
|
||||||
} else if (elementWithid.type === "arrow") {
|
} else if (elementWithid.type === "arrow") {
|
||||||
const { linearElement, startBoundElement, endBoundElement } =
|
const { linearElement, startBoundElement, endBoundElement } =
|
||||||
bindLinearElementToElement(elementWithid);
|
bindLinearElementToElement(elementWithid);
|
||||||
excalidrawElements.push(linearElement);
|
excalidrawElements.add(linearElement);
|
||||||
excalidrawElements.push(startBoundElement);
|
excalidrawElements.add(startBoundElement);
|
||||||
excalidrawElements.push(endBoundElement);
|
excalidrawElements.add(endBoundElement);
|
||||||
} else if (elementWithid.type === "line") {
|
} else if (elementWithid.type === "line") {
|
||||||
const width = elementWithid.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
const width = elementWithid.width || DEFAULT_LINEAR_ELEMENT_PROPS.width;
|
||||||
const height =
|
const height =
|
||||||
|
@ -391,14 +404,14 @@ export const convertToExcalidrawElements = (
|
||||||
],
|
],
|
||||||
...elementWithid,
|
...elementWithid,
|
||||||
});
|
});
|
||||||
excalidrawElements.push(lineElement);
|
excalidrawElements.add(lineElement);
|
||||||
} else {
|
} else {
|
||||||
excalidrawElement = {
|
excalidrawElement = {
|
||||||
...elementWithid,
|
...elementWithid,
|
||||||
width: elementWithid?.width || DEFAULT_DIMENSION,
|
width: elementWithid?.width || DEFAULT_DIMENSION,
|
||||||
height: elementWithid?.height || DEFAULT_DIMENSION,
|
height: elementWithid?.height || DEFAULT_DIMENSION,
|
||||||
} as ExcalidrawGenericElement;
|
} as ExcalidrawGenericElement;
|
||||||
excalidrawElements.push(excalidrawElement);
|
excalidrawElements.add(excalidrawElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue