mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
support labelled arrows
This commit is contained in:
parent
fbf2d533c0
commit
a443d65512
2 changed files with 34 additions and 15 deletions
|
@ -667,13 +667,8 @@ export const convertToExcalidrawElements = (
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (
|
if (isValidTextContainer(element) && element?.label?.text) {
|
||||||
isValidTextContainer(element) &&
|
//@ts-ignore
|
||||||
element?.label?.text &&
|
|
||||||
(element.type === "rectangle" ||
|
|
||||||
element.type === "ellipse" ||
|
|
||||||
element.type === "diamond")
|
|
||||||
) {
|
|
||||||
const elements = bindTextToContainer(element, element.label);
|
const elements = bindTextToContainer(element, element.label);
|
||||||
res.push(...elements);
|
res.push(...elements);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { getFontString, arrayToMap, isTestEnv } from "../utils";
|
||||||
import {
|
import {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
ExcalidrawGenericElement,
|
ExcalidrawGenericElement,
|
||||||
|
ExcalidrawLinearElement,
|
||||||
ExcalidrawTextContainer,
|
ExcalidrawTextContainer,
|
||||||
ExcalidrawTextElement,
|
ExcalidrawTextElement,
|
||||||
ExcalidrawTextElementWithContainer,
|
ExcalidrawTextElementWithContainer,
|
||||||
|
@ -34,7 +35,7 @@ import {
|
||||||
updateOriginalContainerCache,
|
updateOriginalContainerCache,
|
||||||
} from "./textWysiwyg";
|
} from "./textWysiwyg";
|
||||||
import { ExtractSetType, MarkOptional } from "../utility-types";
|
import { ExtractSetType, MarkOptional } from "../utility-types";
|
||||||
import { ElementConstructorOpts } from "./newElement";
|
import { ElementConstructorOpts, newLinearElement } from "./newElement";
|
||||||
|
|
||||||
export const normalizeText = (text: string) => {
|
export const normalizeText = (text: string) => {
|
||||||
return (
|
return (
|
||||||
|
@ -90,7 +91,7 @@ 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,
|
||||||
|
@ -984,15 +985,38 @@ export const getDefaultLineHeight = (fontFamily: FontFamilyValues) => {
|
||||||
export const bindTextToContainer = (
|
export const bindTextToContainer = (
|
||||||
containerProps:
|
containerProps:
|
||||||
| {
|
| {
|
||||||
type: Exclude<ExcalidrawGenericElement["type"], "selection">;
|
type:
|
||||||
|
| Exclude<ExcalidrawGenericElement["type"], "selection">
|
||||||
|
| ExcalidrawLinearElement["type"];
|
||||||
} & MarkOptional<ElementConstructorOpts, "x" | "y">,
|
} & MarkOptional<ElementConstructorOpts, "x" | "y">,
|
||||||
textProps: { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
|
textProps: { text: string } & MarkOptional<ElementConstructorOpts, "x" | "y">,
|
||||||
) => {
|
) => {
|
||||||
const container = newElement({
|
let container;
|
||||||
x: 0,
|
if (containerProps.type === "arrow") {
|
||||||
y: 0,
|
container = newLinearElement({
|
||||||
...containerProps,
|
//@ts-ignore
|
||||||
});
|
x: 0,
|
||||||
|
//@ts-ignore
|
||||||
|
y: 0,
|
||||||
|
//@ts-ignore
|
||||||
|
type: containerProps.type,
|
||||||
|
//@ts-ignore,
|
||||||
|
endArrowhead: containerProps.type === "arrow" ? "arrow" : null,
|
||||||
|
//@ts-ignore
|
||||||
|
points: [
|
||||||
|
[0, 0],
|
||||||
|
[300, 0],
|
||||||
|
],
|
||||||
|
...containerProps,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//@ts-ignore
|
||||||
|
container = newElement({
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
...containerProps,
|
||||||
|
});
|
||||||
|
}
|
||||||
const textElement: ExcalidrawTextElement = newTextElement({
|
const textElement: ExcalidrawTextElement = newTextElement({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue