mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Merge remote-tracking branch 'origin/release' into danieljgeiger-mathjax
This commit is contained in:
commit
4c939cefad
85 changed files with 902 additions and 820 deletions
|
@ -5,7 +5,7 @@ exports[`Test Linear Elements Test bound text element should match styles for te
|
|||
class="excalidraw-wysiwyg"
|
||||
data-type="wysiwyg"
|
||||
dir="auto"
|
||||
style="position: absolute; display: inline-block; min-height: 1em; margin: 0px; padding: 0px; border: 0px; outline: 0; resize: none; background: transparent; overflow: hidden; z-index: var(--zIndex-wysiwyg); word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; box-sizing: content-box; width: 1px; height: 0px; left: 39.5px; top: 20px; transform-origin: 0.5px 0px; transform: translate(0px, 0px) scale(1) rotate(0deg) translate(0px, 0px); text-align: center; vertical-align: middle; color: rgb(0, 0, 0); opacity: 1; filter: var(--theme-filter); max-height: -20px; font: Emoji 20px 20px; line-height: 0px; font-family: Virgil, Segoe UI Emoji;"
|
||||
style="position: absolute; display: inline-block; min-height: 1em; margin: 0px; padding: 0px; border: 0px; outline: 0; resize: none; background: transparent; overflow: hidden; z-index: var(--zIndex-wysiwyg); word-break: break-word; white-space: pre-wrap; overflow-wrap: break-word; box-sizing: content-box; width: 10px; height: 24px; left: 35px; top: 8px; transform-origin: 5px 12px; transform: translate(0px, 0px) scale(1) rotate(0deg) translate(0px, 0px); text-align: center; vertical-align: middle; color: rgb(0, 0, 0); opacity: 1; filter: var(--theme-filter); max-height: -8px; font: Emoji 20px 20px; line-height: 24px; font-family: Virgil, Segoe UI Emoji;"
|
||||
tabindex="0"
|
||||
wrap="off"
|
||||
/>
|
||||
|
|
|
@ -182,3 +182,73 @@ describe("paste text as a single element", () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Paste bound text container", () => {
|
||||
const container = {
|
||||
type: "ellipse",
|
||||
id: "container-id",
|
||||
x: 554.984375,
|
||||
y: 196.0234375,
|
||||
width: 166,
|
||||
height: 187.01953125,
|
||||
roundness: { type: 2 },
|
||||
boundElements: [{ type: "text", id: "text-id" }],
|
||||
};
|
||||
const textElement = {
|
||||
type: "text",
|
||||
id: "text-id",
|
||||
x: 560.51171875,
|
||||
y: 202.033203125,
|
||||
width: 154,
|
||||
height: 175,
|
||||
fontSize: 20,
|
||||
fontFamily: 1,
|
||||
text: "Excalidraw is a\nvirtual \nopensource \nwhiteboard for \nsketching \nhand-drawn like\ndiagrams",
|
||||
baseline: 168,
|
||||
textAlign: "center",
|
||||
verticalAlign: "middle",
|
||||
containerId: container.id,
|
||||
originalText:
|
||||
"Excalidraw is a virtual opensource whiteboard for sketching hand-drawn like diagrams",
|
||||
};
|
||||
|
||||
it("should fix ellipse bounding box", async () => {
|
||||
const data = JSON.stringify({
|
||||
type: "excalidraw/clipboard",
|
||||
elements: [container, textElement],
|
||||
});
|
||||
setClipboardText(data);
|
||||
pasteWithCtrlCmdShiftV();
|
||||
|
||||
await waitFor(async () => {
|
||||
await sleep(1);
|
||||
expect(h.elements.length).toEqual(2);
|
||||
const container = h.elements[0];
|
||||
expect(container.height).toBe(354);
|
||||
expect(container.width).toBe(166);
|
||||
});
|
||||
});
|
||||
|
||||
it("should fix diamond bounding box", async () => {
|
||||
const data = JSON.stringify({
|
||||
type: "excalidraw/clipboard",
|
||||
elements: [
|
||||
{
|
||||
...container,
|
||||
type: "diamond",
|
||||
},
|
||||
textElement,
|
||||
],
|
||||
});
|
||||
setClipboardText(data);
|
||||
pasteWithCtrlCmdShiftV();
|
||||
|
||||
await waitFor(async () => {
|
||||
await sleep(1);
|
||||
expect(h.elements.length).toEqual(2);
|
||||
const container = h.elements[0];
|
||||
expect(container.height).toBe(740);
|
||||
expect(container.width).toBe(166);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -282,7 +282,6 @@ exports[`restoreElements should restore text element correctly passing value for
|
|||
Object {
|
||||
"angle": 0,
|
||||
"backgroundColor": "transparent",
|
||||
"baseline": 0,
|
||||
"boundElements": Array [],
|
||||
"containerId": null,
|
||||
"fillStyle": "hachure",
|
||||
|
@ -312,8 +311,8 @@ Object {
|
|||
"versionNonce": 0,
|
||||
"verticalAlign": "middle",
|
||||
"width": 100,
|
||||
"x": -0.5,
|
||||
"y": 0,
|
||||
"x": -20,
|
||||
"y": -8.4,
|
||||
}
|
||||
`;
|
||||
|
||||
|
@ -321,7 +320,6 @@ exports[`restoreElements should restore text element correctly with unknown font
|
|||
Object {
|
||||
"angle": 0,
|
||||
"backgroundColor": "transparent",
|
||||
"baseline": 0,
|
||||
"boundElements": Array [],
|
||||
"containerId": null,
|
||||
"fillStyle": "hachure",
|
||||
|
|
|
@ -17,8 +17,11 @@ import { KEYS } from "../keys";
|
|||
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||
import { queryByTestId, queryByText } from "@testing-library/react";
|
||||
import { resize, rotate } from "./utils";
|
||||
import { getBoundTextElementPosition, wrapText } from "../element/textElement";
|
||||
import { getMaxContainerWidth } from "../element/newElement";
|
||||
import {
|
||||
getBoundTextElementPosition,
|
||||
wrapText,
|
||||
getMaxContainerWidth,
|
||||
} from "../element/textElement";
|
||||
import * as textElementUtils from "../element/textElement";
|
||||
import { ROUNDNESS } from "../constants";
|
||||
|
||||
|
@ -1028,7 +1031,7 @@ describe("Test Linear Elements", () => {
|
|||
expect({ width: container.width, height: container.height })
|
||||
.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"height": 10,
|
||||
"height": 128,
|
||||
"width": 367,
|
||||
}
|
||||
`);
|
||||
|
@ -1036,8 +1039,8 @@ describe("Test Linear Elements", () => {
|
|||
expect(getBoundTextElementPosition(container, textElement))
|
||||
.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"x": 386.5,
|
||||
"y": 70,
|
||||
"x": 272,
|
||||
"y": 46,
|
||||
}
|
||||
`);
|
||||
expect((h.elements[1] as ExcalidrawTextElementWithContainer).text)
|
||||
|
@ -1049,11 +1052,11 @@ describe("Test Linear Elements", () => {
|
|||
.toMatchInlineSnapshot(`
|
||||
Array [
|
||||
20,
|
||||
60,
|
||||
391.8122896842806,
|
||||
70,
|
||||
36,
|
||||
502,
|
||||
94,
|
||||
205.9061448421403,
|
||||
65,
|
||||
53,
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
@ -1087,7 +1090,7 @@ describe("Test Linear Elements", () => {
|
|||
expect({ width: container.width, height: container.height })
|
||||
.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"height": 0,
|
||||
"height": 128,
|
||||
"width": 340,
|
||||
}
|
||||
`);
|
||||
|
@ -1095,8 +1098,8 @@ describe("Test Linear Elements", () => {
|
|||
expect(getBoundTextElementPosition(container, textElement))
|
||||
.toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"x": 189.5,
|
||||
"y": 20,
|
||||
"x": 75,
|
||||
"y": -4,
|
||||
}
|
||||
`);
|
||||
expect(textElement.text).toMatchInlineSnapshot(`
|
||||
|
|
|
@ -33,7 +33,7 @@ import { actionChangeRoundness } from "../actions/actionProperties";
|
|||
const MW = 200;
|
||||
const TWIDTH = 200;
|
||||
const THEIGHT = 20;
|
||||
const TBASELINE = 15;
|
||||
const TBASELINE = 0;
|
||||
const FONTSIZE = 20;
|
||||
const DBFONTSIZE = 40;
|
||||
const TRFONTSIZE = 60;
|
||||
|
@ -155,11 +155,7 @@ const prepareTest1Subtype = function (
|
|||
return { actions, methods };
|
||||
} as SubtypePrepFn;
|
||||
|
||||
const measureTest2: SubtypeMethods["measureText"] = function (
|
||||
element,
|
||||
next,
|
||||
maxWidth,
|
||||
) {
|
||||
const measureTest2: SubtypeMethods["measureText"] = function (element, next) {
|
||||
const text = next?.text ?? element.text;
|
||||
const customData = next?.customData ?? {};
|
||||
const fontSize = customData.triple
|
||||
|
@ -167,10 +163,10 @@ const measureTest2: SubtypeMethods["measureText"] = function (
|
|||
: next?.fontSize ?? element.fontSize;
|
||||
const fontFamily = element.fontFamily;
|
||||
const fontString = getFontString({ fontSize, fontFamily });
|
||||
const metrics = textElementUtils.measureText(text, fontString, maxWidth);
|
||||
const metrics = textElementUtils.measureText(text, fontString);
|
||||
const width = Math.max(metrics.width - 10, 0);
|
||||
const height = Math.max(metrics.height - 5, 0);
|
||||
return { width, height, baseline: metrics.baseline + 1 };
|
||||
return { width, height, baseline: 1 };
|
||||
};
|
||||
|
||||
const wrapTest2: SubtypeMethods["wrapText"] = function (
|
||||
|
@ -450,12 +446,6 @@ describe("subtypes", () => {
|
|||
height: THEIGHT - 5,
|
||||
baseline: TBASELINE + 1,
|
||||
});
|
||||
const mMetrics = textElementUtils.measureTextElement(el, {}, MW);
|
||||
expect(mMetrics).toStrictEqual({
|
||||
width: Math.min(TWIDTH, MW) - 10,
|
||||
height: THEIGHT - 5,
|
||||
baseline: TBASELINE + 1,
|
||||
});
|
||||
const wrappedText = textElementUtils.wrapTextElement(el, MW);
|
||||
expect(wrappedText).toEqual(
|
||||
`${testString.split(" ").join("\n")}\nHello world.`,
|
||||
|
@ -482,12 +472,6 @@ describe("subtypes", () => {
|
|||
height: 2 * THEIGHT - 5,
|
||||
baseline: 2 * TBASELINE + 1,
|
||||
});
|
||||
const nextFMW = textElementUtils.measureTextElement(el, next, MW);
|
||||
expect(nextFMW).toStrictEqual({
|
||||
width: Math.min(2 * TWIDTH, MW) - 10,
|
||||
height: 2 * THEIGHT - 5,
|
||||
baseline: 2 * TBASELINE + 1,
|
||||
});
|
||||
const nextFWrText = textElementUtils.wrapTextElement(el, MW, next);
|
||||
expect(nextFWrText).toEqual(
|
||||
`${testString.split(" ").join("\n")}\nHELLO World.`,
|
||||
|
@ -501,12 +485,6 @@ describe("subtypes", () => {
|
|||
height: 3 * THEIGHT - 5,
|
||||
baseline: 3 * TBASELINE + 1,
|
||||
});
|
||||
const nextCDMW = textElementUtils.measureTextElement(el, next, MW);
|
||||
expect(nextCDMW).toStrictEqual({
|
||||
width: Math.min(3 * TWIDTH, MW) - 10,
|
||||
height: 3 * THEIGHT - 5,
|
||||
baseline: 3 * TBASELINE + 1,
|
||||
});
|
||||
const nextCDWrText = textElementUtils.wrapTextElement(el, MW, next);
|
||||
expect(nextCDWrText).toEqual(
|
||||
`${testString.split(" ").join("\n")}\nHELLO WORLD.`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue