Compare commits
8 Commits
barnabasmo
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f55ecb96cc | ||
|
|
a6a32b9b29 | ||
|
|
ac0d3059dc | ||
|
|
1161f1b8ba | ||
|
|
204e06b77b | ||
|
|
414182f599 | ||
|
|
b9d27d308e | ||
|
|
3bdaafe4b5 |
@ -615,52 +615,6 @@ export default function ExampleApp({
|
|||||||
const renderMenu = () => {
|
const renderMenu = () => {
|
||||||
return (
|
return (
|
||||||
<MainMenu>
|
<MainMenu>
|
||||||
<MainMenu.Sub>
|
|
||||||
<MainMenu.Sub.Trigger
|
|
||||||
title="Custom trigger"
|
|
||||||
icon={
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
stroke="currentColor"
|
|
||||||
className="w-6 h-6"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
d="M15.042 21.672L13.684 16.6m0 0l-2.51 2.225.569-9.47 5.227 7.917-3.286-.672zm-7.518-.267A8.25 8.25 0 1120.25 10.5M8.288 14.212A5.25 5.25 0 1117.25 10.5"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Submenu trigger
|
|
||||||
</MainMenu.Sub.Trigger>
|
|
||||||
<MainMenu.Sub.Content>
|
|
||||||
<MainMenu.Sub.Item
|
|
||||||
icon={
|
|
||||||
<svg
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
fill="none"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
strokeWidth={1.5}
|
|
||||||
stroke="currentColor"
|
|
||||||
className="w-6 h-6"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
}
|
|
||||||
onSelect={() => window.alert("You clicked on sub item")}
|
|
||||||
>
|
|
||||||
Sub item
|
|
||||||
</MainMenu.Sub.Item>
|
|
||||||
</MainMenu.Sub.Content>
|
|
||||||
</MainMenu.Sub>
|
|
||||||
<MainMenu.DefaultItems.SaveAsImage />
|
<MainMenu.DefaultItems.SaveAsImage />
|
||||||
<MainMenu.DefaultItems.Export />
|
<MainMenu.DefaultItems.Export />
|
||||||
<MainMenu.Separator />
|
<MainMenu.Separator />
|
||||||
@ -668,57 +622,10 @@ export default function ExampleApp({
|
|||||||
isCollaborating={isCollaborating}
|
isCollaborating={isCollaborating}
|
||||||
onSelect={() => window.alert("You clicked on collab button")}
|
onSelect={() => window.alert("You clicked on collab button")}
|
||||||
/>
|
/>
|
||||||
<MainMenu.Sub>
|
|
||||||
<MainMenu.Sub.Trigger>Trigger</MainMenu.Sub.Trigger>
|
|
||||||
<MainMenu.Sub.Content>
|
|
||||||
<MainMenu.Sub.Item
|
|
||||||
onSelect={() => window.alert("You clicked on sub item")}
|
|
||||||
>
|
|
||||||
Sub item
|
|
||||||
</MainMenu.Sub.Item>
|
|
||||||
</MainMenu.Sub.Content>
|
|
||||||
</MainMenu.Sub>
|
|
||||||
<MainMenu.Group title="Excalidraw links">
|
<MainMenu.Group title="Excalidraw links">
|
||||||
<MainMenu.DefaultItems.Socials />
|
<MainMenu.DefaultItems.Socials />
|
||||||
</MainMenu.Group>
|
</MainMenu.Group>
|
||||||
{/* <MainMenu.Separator /> */}
|
<MainMenu.Separator />
|
||||||
<MainMenu.Sub>
|
|
||||||
<MainMenu.Sub.Trigger className="custom-classname">
|
|
||||||
Another submenu trigger
|
|
||||||
</MainMenu.Sub.Trigger>
|
|
||||||
<MainMenu.Sub.Content className="custom-classname-for-content">
|
|
||||||
<MainMenu.Sub.Item
|
|
||||||
title="Sub item"
|
|
||||||
onSelect={() => window.alert("You clicked on sub item")}
|
|
||||||
>
|
|
||||||
Sub item
|
|
||||||
</MainMenu.Sub.Item>
|
|
||||||
</MainMenu.Sub.Content>
|
|
||||||
</MainMenu.Sub>
|
|
||||||
<MainMenu.Sub>
|
|
||||||
<MainMenu.Sub.Trigger>Trigger me</MainMenu.Sub.Trigger>
|
|
||||||
<MainMenu.Sub.Content>
|
|
||||||
<MainMenu.Sub>
|
|
||||||
<MainMenu.Sub.Trigger>Trigger me inside</MainMenu.Sub.Trigger>
|
|
||||||
<MainMenu.Sub.Content>
|
|
||||||
<MainMenu.Sub.Item
|
|
||||||
onSelect={() => {
|
|
||||||
alert("wow, nested submenus!");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Item wow
|
|
||||||
</MainMenu.Sub.Item>
|
|
||||||
</MainMenu.Sub.Content>
|
|
||||||
</MainMenu.Sub>
|
|
||||||
<MainMenu.Sub.Item
|
|
||||||
onSelect={() => {
|
|
||||||
alert("wow, nested submenus! very cool");
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Another one
|
|
||||||
</MainMenu.Sub.Item>
|
|
||||||
</MainMenu.Sub.Content>
|
|
||||||
</MainMenu.Sub>
|
|
||||||
<MainMenu.ItemCustom>
|
<MainMenu.ItemCustom>
|
||||||
<button
|
<button
|
||||||
style={{ height: "2rem" }}
|
style={{ height: "2rem" }}
|
||||||
|
|||||||
@ -8,7 +8,8 @@ export const SYNC_BROWSER_TABS_TIMEOUT = 50;
|
|||||||
export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
|
export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
|
||||||
export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
|
export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
|
||||||
|
|
||||||
export const FILE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024; // 3 MiB
|
// should be aligned with MAX_ALLOWED_FILE_BYTES
|
||||||
|
export const FILE_UPLOAD_MAX_BYTES = 4 * 1024 * 1024; // 4 MiB
|
||||||
// 1 year (https://stackoverflow.com/a/25201898/927631)
|
// 1 year (https://stackoverflow.com/a/25201898/927631)
|
||||||
export const FILE_CACHE_MAX_AGE_SEC = 31536000;
|
export const FILE_CACHE_MAX_AGE_SEC = 31536000;
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,6 @@ export const AppMainMenu: React.FC<{
|
|||||||
<MainMenu.DefaultItems.SearchMenu />
|
<MainMenu.DefaultItems.SearchMenu />
|
||||||
<MainMenu.DefaultItems.Help />
|
<MainMenu.DefaultItems.Help />
|
||||||
<MainMenu.DefaultItems.ClearCanvas />
|
<MainMenu.DefaultItems.ClearCanvas />
|
||||||
<MainMenu.DefaultItems.Preferences />
|
|
||||||
<MainMenu.Separator />
|
<MainMenu.Separator />
|
||||||
<MainMenu.ItemLink
|
<MainMenu.ItemLink
|
||||||
icon={ExcalLogo}
|
icon={ExcalLogo}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ describe("Test MobileMenu", () => {
|
|||||||
},
|
},
|
||||||
"isTouchScreen": false,
|
"isTouchScreen": false,
|
||||||
"viewport": {
|
"viewport": {
|
||||||
"isLandscape": false,
|
"isLandscape": true,
|
||||||
"isMobile": true,
|
"isMobile": true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -129,6 +129,7 @@ export const CLASSES = {
|
|||||||
ZOOM_ACTIONS: "zoom-actions",
|
ZOOM_ACTIONS: "zoom-actions",
|
||||||
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
||||||
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
||||||
|
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
||||||
@ -259,13 +260,17 @@ export const IMAGE_MIME_TYPES = {
|
|||||||
jfif: "image/jfif",
|
jfif: "image/jfif",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const MIME_TYPES = {
|
export const STRING_MIME_TYPES = {
|
||||||
text: "text/plain",
|
text: "text/plain",
|
||||||
html: "text/html",
|
html: "text/html",
|
||||||
json: "application/json",
|
json: "application/json",
|
||||||
// excalidraw data
|
// excalidraw data
|
||||||
excalidraw: "application/vnd.excalidraw+json",
|
excalidraw: "application/vnd.excalidraw+json",
|
||||||
excalidrawlib: "application/vnd.excalidrawlib+json",
|
excalidrawlib: "application/vnd.excalidrawlib+json",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const MIME_TYPES = {
|
||||||
|
...STRING_MIME_TYPES,
|
||||||
// image-encoded excalidraw data
|
// image-encoded excalidraw data
|
||||||
"excalidraw.svg": "image/svg+xml",
|
"excalidraw.svg": "image/svg+xml",
|
||||||
"excalidraw.png": "image/png",
|
"excalidraw.png": "image/png",
|
||||||
@ -342,10 +347,17 @@ export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
|
|||||||
|
|
||||||
// breakpoints
|
// breakpoints
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// md screen
|
|
||||||
export const MQ_MAX_WIDTH_PORTRAIT = 730;
|
// mobile: up to 699px
|
||||||
export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
|
export const MQ_MAX_MOBILE = 599;
|
||||||
export const MQ_MAX_HEIGHT_LANDSCAPE = 500;
|
|
||||||
|
// tablets
|
||||||
|
export const MQ_MIN_TABLET = MQ_MAX_MOBILE + 1; // lower bound (excludes phones)
|
||||||
|
export const MQ_MAX_TABLET = 1400; // upper bound (excludes laptops/desktops)
|
||||||
|
|
||||||
|
// desktop/laptop
|
||||||
|
export const MQ_MIN_WIDTH_DESKTOP = 1440;
|
||||||
|
|
||||||
// sidebar
|
// sidebar
|
||||||
export const MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
|
export const MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@ -21,6 +21,8 @@ import {
|
|||||||
FONT_FAMILY,
|
FONT_FAMILY,
|
||||||
getFontFamilyFallbacks,
|
getFontFamilyFallbacks,
|
||||||
isDarwin,
|
isDarwin,
|
||||||
|
isAndroid,
|
||||||
|
isIOS,
|
||||||
WINDOWS_EMOJI_FALLBACK_FONT,
|
WINDOWS_EMOJI_FALLBACK_FONT,
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
|
|
||||||
@ -1278,3 +1280,59 @@ export const reduceToCommonValue = <T, R = T>(
|
|||||||
|
|
||||||
return commonValue;
|
return commonValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isMobileOrTablet = (): boolean => {
|
||||||
|
const ua = navigator.userAgent || "";
|
||||||
|
const platform = navigator.platform || "";
|
||||||
|
const uaData = (navigator as any).userAgentData as
|
||||||
|
| { mobile?: boolean; platform?: string }
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
// --- 1) chromium: prefer ua client hints -------------------------------
|
||||||
|
if (uaData) {
|
||||||
|
const plat = (uaData.platform || "").toLowerCase();
|
||||||
|
const isDesktopOS =
|
||||||
|
plat === "windows" ||
|
||||||
|
plat === "macos" ||
|
||||||
|
plat === "linux" ||
|
||||||
|
plat === "chrome os";
|
||||||
|
if (uaData.mobile === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (uaData.mobile === false && plat === "android") {
|
||||||
|
const looksTouchTablet =
|
||||||
|
matchMedia?.("(hover: none)").matches &&
|
||||||
|
matchMedia?.("(pointer: coarse)").matches;
|
||||||
|
return looksTouchTablet;
|
||||||
|
}
|
||||||
|
if (isDesktopOS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 2) ios (includes ipad) --------------------------------------------
|
||||||
|
if (isIOS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 3) android legacy ua fallback -------------------------------------
|
||||||
|
if (isAndroid) {
|
||||||
|
const isAndroidPhone = /Mobile/i.test(ua);
|
||||||
|
const isAndroidTablet = !isAndroidPhone;
|
||||||
|
if (isAndroidPhone || isAndroidTablet) {
|
||||||
|
const looksTouchTablet =
|
||||||
|
matchMedia?.("(hover: none)").matches &&
|
||||||
|
matchMedia?.("(pointer: coarse)").matches;
|
||||||
|
return looksTouchTablet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 4) last resort desktop exclusion ----------------------------------
|
||||||
|
const looksDesktopPlatform =
|
||||||
|
/Win|Linux|CrOS|Mac/.test(platform) ||
|
||||||
|
/Windows NT|X11|CrOS|Macintosh/.test(ua);
|
||||||
|
if (looksDesktopPlatform) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|||||||
@ -1126,7 +1126,9 @@ export interface BoundingBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getCommonBoundingBox = (
|
export const getCommonBoundingBox = (
|
||||||
elements: ExcalidrawElement[] | readonly NonDeleted<ExcalidrawElement>[],
|
elements:
|
||||||
|
| readonly ExcalidrawElement[]
|
||||||
|
| readonly NonDeleted<ExcalidrawElement>[],
|
||||||
): BoundingBox => {
|
): BoundingBox => {
|
||||||
const [minX, minY, maxX, maxY] = getCommonBounds(elements);
|
const [minX, minY, maxX, maxY] = getCommonBounds(elements);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -97,6 +97,7 @@ export * from "./image";
|
|||||||
export * from "./linearElementEditor";
|
export * from "./linearElementEditor";
|
||||||
export * from "./mutateElement";
|
export * from "./mutateElement";
|
||||||
export * from "./newElement";
|
export * from "./newElement";
|
||||||
|
export * from "./positionElementsOnGrid";
|
||||||
export * from "./renderElement";
|
export * from "./renderElement";
|
||||||
export * from "./resizeElements";
|
export * from "./resizeElements";
|
||||||
export * from "./resizeTest";
|
export * from "./resizeTest";
|
||||||
|
|||||||
112
packages/element/src/positionElementsOnGrid.ts
Normal file
112
packages/element/src/positionElementsOnGrid.ts
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
import { getCommonBounds } from "./bounds";
|
||||||
|
import { type ElementUpdate, newElementWith } from "./mutateElement";
|
||||||
|
|
||||||
|
import type { ExcalidrawElement } from "./types";
|
||||||
|
|
||||||
|
// TODO rewrite (mostly vibe-coded)
|
||||||
|
export const positionElementsOnGrid = <TElement extends ExcalidrawElement>(
|
||||||
|
elements: TElement[] | TElement[][],
|
||||||
|
centerX: number,
|
||||||
|
centerY: number,
|
||||||
|
padding = 50,
|
||||||
|
): TElement[] => {
|
||||||
|
// Ensure there are elements to position
|
||||||
|
if (!elements || elements.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const res: TElement[] = [];
|
||||||
|
// Normalize input to work with atomic units (groups of elements)
|
||||||
|
// If elements is a flat array, treat each element as its own atomic unit
|
||||||
|
const atomicUnits: TElement[][] = Array.isArray(elements[0])
|
||||||
|
? (elements as TElement[][])
|
||||||
|
: (elements as TElement[]).map((element) => [element]);
|
||||||
|
|
||||||
|
// Determine the number of columns for atomic units
|
||||||
|
// A common approach for a "grid-like" layout without specific column constraints
|
||||||
|
// is to aim for a roughly square arrangement.
|
||||||
|
const numUnits = atomicUnits.length;
|
||||||
|
const numColumns = Math.max(1, Math.ceil(Math.sqrt(numUnits)));
|
||||||
|
|
||||||
|
// Group atomic units into rows based on the calculated number of columns
|
||||||
|
const rows: TElement[][][] = [];
|
||||||
|
for (let i = 0; i < numUnits; i += numColumns) {
|
||||||
|
rows.push(atomicUnits.slice(i, i + numColumns));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate properties for each row (total width, max height)
|
||||||
|
// and the total actual height of all row content.
|
||||||
|
let totalGridActualHeight = 0; // Sum of max heights of rows, without inter-row padding
|
||||||
|
const rowProperties = rows.map((rowUnits) => {
|
||||||
|
let rowWidth = 0;
|
||||||
|
let maxUnitHeightInRow = 0;
|
||||||
|
|
||||||
|
const unitBounds = rowUnits.map((unit) => {
|
||||||
|
const [minX, minY, maxX, maxY] = getCommonBounds(unit);
|
||||||
|
return {
|
||||||
|
elements: unit,
|
||||||
|
bounds: [minX, minY, maxX, maxY] as const,
|
||||||
|
width: maxX - minX,
|
||||||
|
height: maxY - minY,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
unitBounds.forEach((unitBound, index) => {
|
||||||
|
rowWidth += unitBound.width;
|
||||||
|
// Add padding between units in the same row, but not after the last one
|
||||||
|
if (index < unitBounds.length - 1) {
|
||||||
|
rowWidth += padding;
|
||||||
|
}
|
||||||
|
if (unitBound.height > maxUnitHeightInRow) {
|
||||||
|
maxUnitHeightInRow = unitBound.height;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
totalGridActualHeight += maxUnitHeightInRow;
|
||||||
|
return {
|
||||||
|
unitBounds,
|
||||||
|
width: rowWidth,
|
||||||
|
maxHeight: maxUnitHeightInRow,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Calculate the total height of the grid including padding between rows
|
||||||
|
const totalGridHeightWithPadding =
|
||||||
|
totalGridActualHeight + Math.max(0, rows.length - 1) * padding;
|
||||||
|
|
||||||
|
// Calculate the starting Y position to center the entire grid vertically around centerY
|
||||||
|
let currentY = centerY - totalGridHeightWithPadding / 2;
|
||||||
|
|
||||||
|
// Position atomic units row by row
|
||||||
|
rowProperties.forEach((rowProp) => {
|
||||||
|
const { unitBounds, width: rowWidth, maxHeight: rowMaxHeight } = rowProp;
|
||||||
|
|
||||||
|
// Calculate the starting X for the current row to center it horizontally around centerX
|
||||||
|
let currentX = centerX - rowWidth / 2;
|
||||||
|
|
||||||
|
unitBounds.forEach((unitBound) => {
|
||||||
|
// Calculate the offset needed to position this atomic unit
|
||||||
|
const [originalMinX, originalMinY] = unitBound.bounds;
|
||||||
|
const offsetX = currentX - originalMinX;
|
||||||
|
const offsetY = currentY - originalMinY;
|
||||||
|
|
||||||
|
// Apply the offset to all elements in this atomic unit
|
||||||
|
unitBound.elements.forEach((element) => {
|
||||||
|
res.push(
|
||||||
|
newElementWith(element, {
|
||||||
|
x: element.x + offsetX,
|
||||||
|
y: element.y + offsetY,
|
||||||
|
} as ElementUpdate<TElement>),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Move X for the next unit in the row
|
||||||
|
currentX += unitBound.width + padding;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Move Y to the starting position for the next row
|
||||||
|
// This accounts for the tallest unit in the current row and the inter-row padding
|
||||||
|
currentY += rowMaxHeight + padding;
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
};
|
||||||
@ -1,7 +1,14 @@
|
|||||||
import rough from "roughjs/bin/rough";
|
import rough from "roughjs/bin/rough";
|
||||||
import { getStroke } from "perfect-freehand";
|
import { getStroke } from "perfect-freehand";
|
||||||
|
|
||||||
import { isRightAngleRads } from "@excalidraw/math";
|
import {
|
||||||
|
type GlobalPoint,
|
||||||
|
isRightAngleRads,
|
||||||
|
lineSegment,
|
||||||
|
pointFrom,
|
||||||
|
pointRotateRads,
|
||||||
|
type Radians,
|
||||||
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BOUND_TEXT_PADDING,
|
BOUND_TEXT_PADDING,
|
||||||
@ -14,6 +21,7 @@ import {
|
|||||||
getFontString,
|
getFontString,
|
||||||
isRTL,
|
isRTL,
|
||||||
getVerticalOffset,
|
getVerticalOffset,
|
||||||
|
invariant,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@ -32,7 +40,7 @@ import type {
|
|||||||
InteractiveCanvasRenderConfig,
|
InteractiveCanvasRenderConfig,
|
||||||
} from "@excalidraw/excalidraw/scene/types";
|
} from "@excalidraw/excalidraw/scene/types";
|
||||||
|
|
||||||
import { getElementAbsoluteCoords } from "./bounds";
|
import { getElementAbsoluteCoords, getElementBounds } from "./bounds";
|
||||||
import { getUncroppedImageElement } from "./cropElement";
|
import { getUncroppedImageElement } from "./cropElement";
|
||||||
import { LinearElementEditor } from "./linearElementEditor";
|
import { LinearElementEditor } from "./linearElementEditor";
|
||||||
import {
|
import {
|
||||||
@ -1039,6 +1047,66 @@ export function getFreeDrawPath2D(element: ExcalidrawFreeDrawElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getFreeDrawSvgPath(element: ExcalidrawFreeDrawElement) {
|
export function getFreeDrawSvgPath(element: ExcalidrawFreeDrawElement) {
|
||||||
|
return getSvgPathFromStroke(getFreedrawOutlinePoints(element));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFreedrawOutlineAsSegments(
|
||||||
|
element: ExcalidrawFreeDrawElement,
|
||||||
|
points: [number, number][],
|
||||||
|
elementsMap: ElementsMap,
|
||||||
|
) {
|
||||||
|
const bounds = getElementBounds(
|
||||||
|
{
|
||||||
|
...element,
|
||||||
|
angle: 0 as Radians,
|
||||||
|
},
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
const center = pointFrom<GlobalPoint>(
|
||||||
|
(bounds[0] + bounds[2]) / 2,
|
||||||
|
(bounds[1] + bounds[3]) / 2,
|
||||||
|
);
|
||||||
|
|
||||||
|
invariant(points.length >= 2, "Freepath outline must have at least 2 points");
|
||||||
|
|
||||||
|
return points.slice(2).reduce(
|
||||||
|
(acc, curr) => {
|
||||||
|
acc.push(
|
||||||
|
lineSegment<GlobalPoint>(
|
||||||
|
acc[acc.length - 1][1],
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(curr[0] + element.x, curr[1] + element.y),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
[
|
||||||
|
lineSegment<GlobalPoint>(
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
points[0][0] + element.x,
|
||||||
|
points[0][1] + element.y,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
pointRotateRads(
|
||||||
|
pointFrom<GlobalPoint>(
|
||||||
|
points[1][0] + element.x,
|
||||||
|
points[1][1] + element.y,
|
||||||
|
),
|
||||||
|
center,
|
||||||
|
element.angle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getFreedrawOutlinePoints(element: ExcalidrawFreeDrawElement) {
|
||||||
// If input points are empty (should they ever be?) return a dot
|
// If input points are empty (should they ever be?) return a dot
|
||||||
const inputPoints = element.simulatePressure
|
const inputPoints = element.simulatePressure
|
||||||
? element.points
|
? element.points
|
||||||
@ -1057,7 +1125,7 @@ export function getFreeDrawSvgPath(element: ExcalidrawFreeDrawElement) {
|
|||||||
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
||||||
};
|
};
|
||||||
|
|
||||||
return getSvgPathFromStroke(getStroke(inputPoints as number[][], options));
|
return getStroke(inputPoints as number[][], options) as [number, number][];
|
||||||
}
|
}
|
||||||
|
|
||||||
function med(A: number[], B: number[]) {
|
function med(A: number[], B: number[]) {
|
||||||
|
|||||||
@ -69,7 +69,7 @@ export const actionChangeViewBackgroundColor = register({
|
|||||||
: CaptureUpdateAction.EVENTUALLY,
|
: CaptureUpdateAction.EVENTUALLY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, appProps }) => {
|
PanelComponent: ({ elements, appState, updateData, appProps, data }) => {
|
||||||
// FIXME move me to src/components/mainMenu/DefaultItems.tsx
|
// FIXME move me to src/components/mainMenu/DefaultItems.tsx
|
||||||
return (
|
return (
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
@ -83,6 +83,7 @@ export const actionChangeViewBackgroundColor = register({
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
updateData={updateData}
|
updateData={updateData}
|
||||||
|
compactMode={appState.stylesPanelMode === "compact"}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -88,6 +88,10 @@ export const actionToggleLinearEditor = register({
|
|||||||
selectedElementIds: appState.selectedElementIds,
|
selectedElementIds: appState.selectedElementIds,
|
||||||
})[0] as ExcalidrawLinearElement;
|
})[0] as ExcalidrawLinearElement;
|
||||||
|
|
||||||
|
if (!selectedElement) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const label = t(
|
const label = t(
|
||||||
selectedElement.type === "arrow"
|
selectedElement.type === "arrow"
|
||||||
? "labels.lineEditor.editArrow"
|
? "labels.lineEditor.editArrow"
|
||||||
|
|||||||
@ -137,6 +137,11 @@ import {
|
|||||||
isSomeElementSelected,
|
isSomeElementSelected,
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
|
|
||||||
|
import {
|
||||||
|
withCaretPositionPreservation,
|
||||||
|
restoreCaretPosition,
|
||||||
|
} from "../hooks/useTextEditorFocus";
|
||||||
|
|
||||||
import { register } from "./register";
|
import { register } from "./register";
|
||||||
|
|
||||||
import type { AppClassProperties, AppState, Primitive } from "../types";
|
import type { AppClassProperties, AppState, Primitive } from "../types";
|
||||||
@ -321,9 +326,11 @@ export const actionChangeStrokeColor = register({
|
|||||||
: CaptureUpdateAction.EVENTUALLY,
|
: CaptureUpdateAction.EVENTUALLY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||||
<>
|
<>
|
||||||
|
{appState.stylesPanelMode === "full" && (
|
||||||
<h3 aria-hidden="true">{t("labels.stroke")}</h3>
|
<h3 aria-hidden="true">{t("labels.stroke")}</h3>
|
||||||
|
)}
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
topPicks={DEFAULT_ELEMENT_STROKE_PICKS}
|
topPicks={DEFAULT_ELEMENT_STROKE_PICKS}
|
||||||
palette={DEFAULT_ELEMENT_STROKE_COLOR_PALETTE}
|
palette={DEFAULT_ELEMENT_STROKE_COLOR_PALETTE}
|
||||||
@ -341,6 +348,7 @@ export const actionChangeStrokeColor = register({
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
updateData={updateData}
|
updateData={updateData}
|
||||||
|
compactMode={appState.stylesPanelMode === "compact"}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@ -398,9 +406,11 @@ export const actionChangeBackgroundColor = register({
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||||
<>
|
<>
|
||||||
|
{appState.stylesPanelMode === "full" && (
|
||||||
<h3 aria-hidden="true">{t("labels.background")}</h3>
|
<h3 aria-hidden="true">{t("labels.background")}</h3>
|
||||||
|
)}
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
topPicks={DEFAULT_ELEMENT_BACKGROUND_PICKS}
|
topPicks={DEFAULT_ELEMENT_BACKGROUND_PICKS}
|
||||||
palette={DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE}
|
palette={DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE}
|
||||||
@ -418,6 +428,7 @@ export const actionChangeBackgroundColor = register({
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
updateData={updateData}
|
updateData={updateData}
|
||||||
|
compactMode={appState.stylesPanelMode === "compact"}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@ -518,9 +529,11 @@ export const actionChangeStrokeWidth = register({
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
{appState.stylesPanelMode === "full" && (
|
||||||
<legend>{t("labels.strokeWidth")}</legend>
|
<legend>{t("labels.strokeWidth")}</legend>
|
||||||
|
)}
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
<RadioSelection
|
<RadioSelection
|
||||||
group="stroke-width"
|
group="stroke-width"
|
||||||
@ -575,9 +588,11 @@ export const actionChangeSloppiness = register({
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
{appState.stylesPanelMode === "full" && (
|
||||||
<legend>{t("labels.sloppiness")}</legend>
|
<legend>{t("labels.sloppiness")}</legend>
|
||||||
|
)}
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
<RadioSelection
|
<RadioSelection
|
||||||
group="sloppiness"
|
group="sloppiness"
|
||||||
@ -628,9 +643,11 @@ export const actionChangeStrokeStyle = register({
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
{appState.stylesPanelMode === "full" && (
|
||||||
<legend>{t("labels.strokeStyle")}</legend>
|
<legend>{t("labels.strokeStyle")}</legend>
|
||||||
|
)}
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
<RadioSelection
|
<RadioSelection
|
||||||
group="strokeStyle"
|
group="strokeStyle"
|
||||||
@ -697,7 +714,7 @@ export const actionChangeFontSize = register({
|
|||||||
perform: (elements, appState, value, app) => {
|
perform: (elements, appState, value, app) => {
|
||||||
return changeFontSize(elements, appState, app, () => value, value);
|
return changeFontSize(elements, appState, app, () => value, value);
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.fontSize")}</legend>
|
<legend>{t("labels.fontSize")}</legend>
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
@ -756,7 +773,14 @@ export const actionChangeFontSize = register({
|
|||||||
? null
|
? null
|
||||||
: appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
: appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => {
|
||||||
|
withCaretPositionPreservation(
|
||||||
|
() => updateData(value),
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
|
!!appState.editingTextElement,
|
||||||
|
data?.onPreventClose,
|
||||||
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@ -1016,7 +1040,7 @@ export const actionChangeFontFamily = register({
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, app, updateData }) => {
|
PanelComponent: ({ elements, appState, app, updateData, data }) => {
|
||||||
const cachedElementsRef = useRef<ElementsMap>(new Map());
|
const cachedElementsRef = useRef<ElementsMap>(new Map());
|
||||||
const prevSelectedFontFamilyRef = useRef<number | null>(null);
|
const prevSelectedFontFamilyRef = useRef<number | null>(null);
|
||||||
// relying on state batching as multiple `FontPicker` handlers could be called in rapid succession and we want to combine them
|
// relying on state batching as multiple `FontPicker` handlers could be called in rapid succession and we want to combine them
|
||||||
@ -1094,20 +1118,28 @@ export const actionChangeFontFamily = register({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
{appState.stylesPanelMode === "full" && (
|
||||||
<legend>{t("labels.fontFamily")}</legend>
|
<legend>{t("labels.fontFamily")}</legend>
|
||||||
|
)}
|
||||||
<FontPicker
|
<FontPicker
|
||||||
isOpened={appState.openPopup === "fontFamily"}
|
isOpened={appState.openPopup === "fontFamily"}
|
||||||
selectedFontFamily={selectedFontFamily}
|
selectedFontFamily={selectedFontFamily}
|
||||||
hoveredFontFamily={appState.currentHoveredFontFamily}
|
hoveredFontFamily={appState.currentHoveredFontFamily}
|
||||||
|
compactMode={appState.stylesPanelMode === "compact"}
|
||||||
onSelect={(fontFamily) => {
|
onSelect={(fontFamily) => {
|
||||||
|
withCaretPositionPreservation(
|
||||||
|
() => {
|
||||||
setBatchedData({
|
setBatchedData({
|
||||||
openPopup: null,
|
openPopup: null,
|
||||||
currentHoveredFontFamily: null,
|
currentHoveredFontFamily: null,
|
||||||
currentItemFontFamily: fontFamily,
|
currentItemFontFamily: fontFamily,
|
||||||
});
|
});
|
||||||
|
|
||||||
// defensive clear so immediate close won't abuse the cached elements
|
// defensive clear so immediate close won't abuse the cached elements
|
||||||
cachedElementsRef.current.clear();
|
cachedElementsRef.current.clear();
|
||||||
|
},
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
|
!!appState.editingTextElement,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
onHover={(fontFamily) => {
|
onHover={(fontFamily) => {
|
||||||
setBatchedData({
|
setBatchedData({
|
||||||
@ -1164,25 +1196,28 @@ export const actionChangeFontFamily = register({
|
|||||||
}
|
}
|
||||||
|
|
||||||
setBatchedData({
|
setBatchedData({
|
||||||
|
...batchedData,
|
||||||
openPopup: "fontFamily",
|
openPopup: "fontFamily",
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// close, use the cache and clear it afterwards
|
const fontFamilyData = {
|
||||||
const data = {
|
|
||||||
openPopup: null,
|
|
||||||
currentHoveredFontFamily: null,
|
currentHoveredFontFamily: null,
|
||||||
cachedElements: new Map(cachedElementsRef.current),
|
cachedElements: new Map(cachedElementsRef.current),
|
||||||
resetAll: true,
|
resetAll: true,
|
||||||
} as ChangeFontFamilyData;
|
} as ChangeFontFamilyData;
|
||||||
|
|
||||||
if (isUnmounted.current) {
|
setBatchedData({
|
||||||
// in case the component was unmounted by the parent, trigger the update directly
|
...fontFamilyData,
|
||||||
updateData({ ...batchedData, ...data });
|
});
|
||||||
} else {
|
|
||||||
setBatchedData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedElementsRef.current.clear();
|
cachedElementsRef.current.clear();
|
||||||
|
|
||||||
|
// Refocus text editor when font picker closes if we were editing text
|
||||||
|
if (
|
||||||
|
appState.stylesPanelMode === "compact" &&
|
||||||
|
appState.editingTextElement
|
||||||
|
) {
|
||||||
|
restoreCaretPosition(null); // Just refocus without saved position
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@ -1225,8 +1260,9 @@ export const actionChangeTextAlign = register({
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => {
|
PanelComponent: ({ elements, appState, updateData, app, data }) => {
|
||||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{t("labels.textAlign")}</legend>
|
<legend>{t("labels.textAlign")}</legend>
|
||||||
@ -1275,7 +1311,14 @@ export const actionChangeTextAlign = register({
|
|||||||
(hasSelection) =>
|
(hasSelection) =>
|
||||||
hasSelection ? null : appState.currentItemTextAlign,
|
hasSelection ? null : appState.currentItemTextAlign,
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => {
|
||||||
|
withCaretPositionPreservation(
|
||||||
|
() => updateData(value),
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
|
!!appState.editingTextElement,
|
||||||
|
data?.onPreventClose,
|
||||||
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@ -1317,7 +1360,7 @@ export const actionChangeVerticalAlign = register({
|
|||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
PanelComponent: ({ elements, appState, updateData, app }) => {
|
PanelComponent: ({ elements, appState, updateData, app, data }) => {
|
||||||
return (
|
return (
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
@ -1367,7 +1410,14 @@ export const actionChangeVerticalAlign = register({
|
|||||||
) !== null,
|
) !== null,
|
||||||
(hasSelection) => (hasSelection ? null : VERTICAL_ALIGN.MIDDLE),
|
(hasSelection) => (hasSelection ? null : VERTICAL_ALIGN.MIDDLE),
|
||||||
)}
|
)}
|
||||||
onChange={(value) => updateData(value)}
|
onChange={(value) => {
|
||||||
|
withCaretPositionPreservation(
|
||||||
|
() => updateData(value),
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
|
!!appState.editingTextElement,
|
||||||
|
data?.onPreventClose,
|
||||||
|
);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@ -1616,6 +1666,25 @@ export const actionChangeArrowhead = register({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const actionChangeArrowProperties = register({
|
||||||
|
name: "changeArrowProperties",
|
||||||
|
label: "Change arrow properties",
|
||||||
|
trackEvent: false,
|
||||||
|
perform: (elements, appState, value, app) => {
|
||||||
|
// This action doesn't perform any changes directly
|
||||||
|
// It's just a container for the arrow type and arrowhead actions
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
PanelComponent: ({ elements, appState, updateData, app, renderAction }) => {
|
||||||
|
return (
|
||||||
|
<div className="selected-shape-actions">
|
||||||
|
{renderAction("changeArrowType")}
|
||||||
|
{renderAction("changeArrowhead")}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const actionChangeArrowType = register({
|
export const actionChangeArrowType = register({
|
||||||
name: "changeArrowType",
|
name: "changeArrowType",
|
||||||
label: "Change arrow types",
|
label: "Change arrow types",
|
||||||
|
|||||||
@ -18,6 +18,7 @@ export {
|
|||||||
actionChangeFontFamily,
|
actionChangeFontFamily,
|
||||||
actionChangeTextAlign,
|
actionChangeTextAlign,
|
||||||
actionChangeVerticalAlign,
|
actionChangeVerticalAlign,
|
||||||
|
actionChangeArrowProperties,
|
||||||
} from "./actionProperties";
|
} from "./actionProperties";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@ -54,8 +54,7 @@ export type ShortcutName =
|
|||||||
| "saveScene"
|
| "saveScene"
|
||||||
| "imageExport"
|
| "imageExport"
|
||||||
| "commandPalette"
|
| "commandPalette"
|
||||||
| "searchMenu"
|
| "searchMenu";
|
||||||
| "toolLock";
|
|
||||||
|
|
||||||
const shortcutMap: Record<ShortcutName, string[]> = {
|
const shortcutMap: Record<ShortcutName, string[]> = {
|
||||||
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
toggleTheme: [getShortcutKey("Shift+Alt+D")],
|
||||||
@ -117,7 +116,6 @@ const shortcutMap: Record<ShortcutName, string[]> = {
|
|||||||
toggleShortcuts: [getShortcutKey("?")],
|
toggleShortcuts: [getShortcutKey("?")],
|
||||||
searchMenu: [getShortcutKey("CtrlOrCmd+F")],
|
searchMenu: [getShortcutKey("CtrlOrCmd+F")],
|
||||||
wrapSelectionInFrame: [],
|
wrapSelectionInFrame: [],
|
||||||
toolLock: [getShortcutKey("Q")],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getShortcutFromShortcutName = (name: ShortcutName, idx = 0) => {
|
export const getShortcutFromShortcutName = (name: ShortcutName, idx = 0) => {
|
||||||
|
|||||||
@ -69,6 +69,7 @@ export type ActionName =
|
|||||||
| "changeStrokeStyle"
|
| "changeStrokeStyle"
|
||||||
| "changeArrowhead"
|
| "changeArrowhead"
|
||||||
| "changeArrowType"
|
| "changeArrowType"
|
||||||
|
| "changeArrowProperties"
|
||||||
| "changeOpacity"
|
| "changeOpacity"
|
||||||
| "changeFontSize"
|
| "changeFontSize"
|
||||||
| "toggleCanvasMenu"
|
| "toggleCanvasMenu"
|
||||||
|
|||||||
@ -123,6 +123,7 @@ export const getDefaultAppState = (): Omit<
|
|||||||
searchMatches: null,
|
searchMatches: null,
|
||||||
lockedMultiSelections: {},
|
lockedMultiSelections: {},
|
||||||
activeLockedId: null,
|
activeLockedId: null,
|
||||||
|
stylesPanelMode: "full",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -247,6 +248,7 @@ const APP_STATE_STORAGE_CONF = (<
|
|||||||
searchMatches: { browser: false, export: false, server: false },
|
searchMatches: { browser: false, export: false, server: false },
|
||||||
lockedMultiSelections: { browser: true, export: true, server: true },
|
lockedMultiSelections: { browser: true, export: true, server: true },
|
||||||
activeLockedId: { browser: false, export: false, server: false },
|
activeLockedId: { browser: false, export: false, server: false },
|
||||||
|
stylesPanelMode: { browser: true, export: false, server: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
const _clearAppStateForStorage = <
|
const _clearAppStateForStorage = <
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
createPasteEvent,
|
createPasteEvent,
|
||||||
parseClipboard,
|
parseClipboard,
|
||||||
|
parseDataTransferEvent,
|
||||||
serializeAsClipboardJSON,
|
serializeAsClipboardJSON,
|
||||||
} from "./clipboard";
|
} from "./clipboard";
|
||||||
import { API } from "./tests/helpers/api";
|
import { API } from "./tests/helpers/api";
|
||||||
@ -13,7 +14,9 @@ describe("parseClipboard()", () => {
|
|||||||
|
|
||||||
text = "123";
|
text = "123";
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({ types: { "text/plain": text } }),
|
createPasteEvent({ types: { "text/plain": text } }),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.text).toBe(text);
|
expect(clipboardData.text).toBe(text);
|
||||||
|
|
||||||
@ -21,7 +24,9 @@ describe("parseClipboard()", () => {
|
|||||||
|
|
||||||
text = "[123]";
|
text = "[123]";
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({ types: { "text/plain": text } }),
|
createPasteEvent({ types: { "text/plain": text } }),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.text).toBe(text);
|
expect(clipboardData.text).toBe(text);
|
||||||
|
|
||||||
@ -29,7 +34,9 @@ describe("parseClipboard()", () => {
|
|||||||
|
|
||||||
text = JSON.stringify({ val: 42 });
|
text = JSON.stringify({ val: 42 });
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({ types: { "text/plain": text } }),
|
createPasteEvent({ types: { "text/plain": text } }),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.text).toBe(text);
|
expect(clipboardData.text).toBe(text);
|
||||||
});
|
});
|
||||||
@ -39,11 +46,13 @@ describe("parseClipboard()", () => {
|
|||||||
|
|
||||||
const json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
const json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||||
const clipboardData = await parseClipboard(
|
const clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/plain": json,
|
"text/plain": json,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.elements).toEqual([rect]);
|
expect(clipboardData.elements).toEqual([rect]);
|
||||||
});
|
});
|
||||||
@ -56,21 +65,25 @@ describe("parseClipboard()", () => {
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": json,
|
"text/html": json,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.elements).toEqual([rect]);
|
expect(clipboardData.elements).toEqual([rect]);
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": `<div> ${json}</div>`,
|
"text/html": `<div> ${json}</div>`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.elements).toEqual([rect]);
|
expect(clipboardData.elements).toEqual([rect]);
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
@ -80,11 +93,13 @@ describe("parseClipboard()", () => {
|
|||||||
let clipboardData;
|
let clipboardData;
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": `<img src="https://example.com/image.png" />`,
|
"text/html": `<img src="https://example.com/image.png" />`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.mixedContent).toEqual([
|
expect(clipboardData.mixedContent).toEqual([
|
||||||
{
|
{
|
||||||
@ -94,11 +109,13 @@ describe("parseClipboard()", () => {
|
|||||||
]);
|
]);
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": `<div><img src="https://example.com/image.png" /></div><a><img src="https://example.com/image2.png" /></a>`,
|
"text/html": `<div><img src="https://example.com/image.png" /></div><a><img src="https://example.com/image2.png" /></a>`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.mixedContent).toEqual([
|
expect(clipboardData.mixedContent).toEqual([
|
||||||
{
|
{
|
||||||
@ -114,11 +131,13 @@ describe("parseClipboard()", () => {
|
|||||||
|
|
||||||
it("should parse text content alongside <image> `src` urls out of text/html", async () => {
|
it("should parse text content alongside <image> `src` urls out of text/html", async () => {
|
||||||
const clipboardData = await parseClipboard(
|
const clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": `<a href="https://example.com">hello </a><div><img src="https://example.com/image.png" /></div><b>my friend!</b>`,
|
"text/html": `<a href="https://example.com">hello </a><div><img src="https://example.com/image.png" /></div><b>my friend!</b>`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.mixedContent).toEqual([
|
expect(clipboardData.mixedContent).toEqual([
|
||||||
{
|
{
|
||||||
@ -141,6 +160,7 @@ describe("parseClipboard()", () => {
|
|||||||
let clipboardData;
|
let clipboardData;
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/plain": `a b
|
"text/plain": `a b
|
||||||
@ -149,6 +169,7 @@ describe("parseClipboard()", () => {
|
|||||||
7 10`,
|
7 10`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.spreadsheet).toEqual({
|
expect(clipboardData.spreadsheet).toEqual({
|
||||||
title: "b",
|
title: "b",
|
||||||
@ -157,6 +178,7 @@ describe("parseClipboard()", () => {
|
|||||||
});
|
});
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": `a b
|
"text/html": `a b
|
||||||
@ -165,6 +187,7 @@ describe("parseClipboard()", () => {
|
|||||||
7 10`,
|
7 10`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.spreadsheet).toEqual({
|
expect(clipboardData.spreadsheet).toEqual({
|
||||||
title: "b",
|
title: "b",
|
||||||
@ -173,6 +196,7 @@ describe("parseClipboard()", () => {
|
|||||||
});
|
});
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
clipboardData = await parseClipboard(
|
clipboardData = await parseClipboard(
|
||||||
|
await parseDataTransferEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
types: {
|
types: {
|
||||||
"text/html": `<html>
|
"text/html": `<html>
|
||||||
@ -186,6 +210,7 @@ describe("parseClipboard()", () => {
|
|||||||
7 10`,
|
7 10`,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(clipboardData.spreadsheet).toEqual({
|
expect(clipboardData.spreadsheet).toEqual({
|
||||||
title: "b",
|
title: "b",
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
arrayToMap,
|
arrayToMap,
|
||||||
isMemberOf,
|
isMemberOf,
|
||||||
isPromiseLike,
|
isPromiseLike,
|
||||||
|
EVENT,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import { mutateElement } from "@excalidraw/element";
|
import { mutateElement } from "@excalidraw/element";
|
||||||
@ -16,15 +17,26 @@ import {
|
|||||||
|
|
||||||
import { getContainingFrame } from "@excalidraw/element";
|
import { getContainingFrame } from "@excalidraw/element";
|
||||||
|
|
||||||
|
import type { ValueOf } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
|
import type { IMAGE_MIME_TYPES, STRING_MIME_TYPES } from "@excalidraw/common";
|
||||||
import type {
|
import type {
|
||||||
ExcalidrawElement,
|
ExcalidrawElement,
|
||||||
NonDeletedExcalidrawElement,
|
NonDeletedExcalidrawElement,
|
||||||
} from "@excalidraw/element/types";
|
} from "@excalidraw/element/types";
|
||||||
|
|
||||||
import { ExcalidrawError } from "./errors";
|
import { ExcalidrawError } from "./errors";
|
||||||
import { createFile, isSupportedImageFileType } from "./data/blob";
|
import {
|
||||||
|
createFile,
|
||||||
|
getFileHandle,
|
||||||
|
isSupportedImageFileType,
|
||||||
|
normalizeFile,
|
||||||
|
} from "./data/blob";
|
||||||
|
|
||||||
import { tryParseSpreadsheet, VALID_SPREADSHEET } from "./charts";
|
import { tryParseSpreadsheet, VALID_SPREADSHEET } from "./charts";
|
||||||
|
|
||||||
|
import type { FileSystemHandle } from "./data/filesystem";
|
||||||
|
|
||||||
import type { Spreadsheet } from "./charts";
|
import type { Spreadsheet } from "./charts";
|
||||||
|
|
||||||
import type { BinaryFiles } from "./types";
|
import type { BinaryFiles } from "./types";
|
||||||
@ -92,7 +104,7 @@ export const createPasteEvent = ({
|
|||||||
console.warn("createPasteEvent: no types or files provided");
|
console.warn("createPasteEvent: no types or files provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = new ClipboardEvent("paste", {
|
const event = new ClipboardEvent(EVENT.PASTE, {
|
||||||
clipboardData: new DataTransfer(),
|
clipboardData: new DataTransfer(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,10 +113,11 @@ export const createPasteEvent = ({
|
|||||||
if (typeof value !== "string") {
|
if (typeof value !== "string") {
|
||||||
files = files || [];
|
files = files || [];
|
||||||
files.push(value);
|
files.push(value);
|
||||||
|
event.clipboardData?.items.add(value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
event.clipboardData?.setData(type, value);
|
event.clipboardData?.items.add(value, type);
|
||||||
if (event.clipboardData?.getData(type) !== value) {
|
if (event.clipboardData?.getData(type) !== value) {
|
||||||
throw new Error(`Failed to set "${type}" as clipboardData item`);
|
throw new Error(`Failed to set "${type}" as clipboardData item`);
|
||||||
}
|
}
|
||||||
@ -229,14 +242,10 @@ function parseHTMLTree(el: ChildNode) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maybeParseHTMLPaste = (
|
const maybeParseHTMLDataItem = (
|
||||||
event: ClipboardEvent,
|
dataItem: ParsedDataTransferItemType<typeof MIME_TYPES["html"]>,
|
||||||
): { type: "mixedContent"; value: PastedMixedContent } | null => {
|
): { type: "mixedContent"; value: PastedMixedContent } | null => {
|
||||||
const html = event.clipboardData?.getData(MIME_TYPES.html);
|
const html = dataItem.value;
|
||||||
|
|
||||||
if (!html) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const doc = new DOMParser().parseFromString(html, MIME_TYPES.html);
|
const doc = new DOMParser().parseFromString(html, MIME_TYPES.html);
|
||||||
@ -332,18 +341,21 @@ export const readSystemClipboard = async () => {
|
|||||||
* Parses "paste" ClipboardEvent.
|
* Parses "paste" ClipboardEvent.
|
||||||
*/
|
*/
|
||||||
const parseClipboardEventTextData = async (
|
const parseClipboardEventTextData = async (
|
||||||
event: ClipboardEvent,
|
dataList: ParsedDataTranferList,
|
||||||
isPlainPaste = false,
|
isPlainPaste = false,
|
||||||
): Promise<ParsedClipboardEventTextData> => {
|
): Promise<ParsedClipboardEventTextData> => {
|
||||||
try {
|
try {
|
||||||
const mixedContent = !isPlainPaste && event && maybeParseHTMLPaste(event);
|
const htmlItem = dataList.findByType(MIME_TYPES.html);
|
||||||
|
|
||||||
|
const mixedContent =
|
||||||
|
!isPlainPaste && htmlItem && maybeParseHTMLDataItem(htmlItem);
|
||||||
|
|
||||||
if (mixedContent) {
|
if (mixedContent) {
|
||||||
if (mixedContent.value.every((item) => item.type === "text")) {
|
if (mixedContent.value.every((item) => item.type === "text")) {
|
||||||
return {
|
return {
|
||||||
type: "text",
|
type: "text",
|
||||||
value:
|
value:
|
||||||
event.clipboardData?.getData(MIME_TYPES.text) ||
|
dataList.getData(MIME_TYPES.text) ??
|
||||||
mixedContent.value
|
mixedContent.value
|
||||||
.map((item) => item.value)
|
.map((item) => item.value)
|
||||||
.join("\n")
|
.join("\n")
|
||||||
@ -354,23 +366,155 @@ const parseClipboardEventTextData = async (
|
|||||||
return mixedContent;
|
return mixedContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = event.clipboardData?.getData(MIME_TYPES.text);
|
return {
|
||||||
|
type: "text",
|
||||||
return { type: "text", value: (text || "").trim() };
|
value: (dataList.getData(MIME_TYPES.text) || "").trim(),
|
||||||
|
};
|
||||||
} catch {
|
} catch {
|
||||||
return { type: "text", value: "" };
|
return { type: "text", value: "" };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type AllowedParsedDataTransferItem =
|
||||||
|
| {
|
||||||
|
type: ValueOf<typeof IMAGE_MIME_TYPES>;
|
||||||
|
kind: "file";
|
||||||
|
file: File;
|
||||||
|
fileHandle: FileSystemHandle | null;
|
||||||
|
}
|
||||||
|
| { type: ValueOf<typeof STRING_MIME_TYPES>; kind: "string"; value: string };
|
||||||
|
|
||||||
|
type ParsedDataTransferItem =
|
||||||
|
| {
|
||||||
|
type: string;
|
||||||
|
kind: "file";
|
||||||
|
file: File;
|
||||||
|
fileHandle: FileSystemHandle | null;
|
||||||
|
}
|
||||||
|
| { type: string; kind: "string"; value: string };
|
||||||
|
|
||||||
|
type ParsedDataTransferItemType<
|
||||||
|
T extends AllowedParsedDataTransferItem["type"],
|
||||||
|
> = AllowedParsedDataTransferItem & { type: T };
|
||||||
|
|
||||||
|
export type ParsedDataTransferFile = Extract<
|
||||||
|
AllowedParsedDataTransferItem,
|
||||||
|
{ kind: "file" }
|
||||||
|
>;
|
||||||
|
|
||||||
|
type ParsedDataTranferList = ParsedDataTransferItem[] & {
|
||||||
|
/**
|
||||||
|
* Only allows filtering by known `string` data types, since `file`
|
||||||
|
* types can have multiple items of the same type (e.g. multiple image files)
|
||||||
|
* unlike `string` data transfer items.
|
||||||
|
*/
|
||||||
|
findByType: typeof findDataTransferItemType;
|
||||||
|
/**
|
||||||
|
* Only allows filtering by known `string` data types, since `file`
|
||||||
|
* types can have multiple items of the same type (e.g. multiple image files)
|
||||||
|
* unlike `string` data transfer items.
|
||||||
|
*/
|
||||||
|
getData: typeof getDataTransferItemData;
|
||||||
|
getFiles: typeof getDataTransferFiles;
|
||||||
|
};
|
||||||
|
|
||||||
|
const findDataTransferItemType = function <
|
||||||
|
T extends ValueOf<typeof STRING_MIME_TYPES>,
|
||||||
|
>(this: ParsedDataTranferList, type: T): ParsedDataTransferItemType<T> | null {
|
||||||
|
return (
|
||||||
|
this.find(
|
||||||
|
(item): item is ParsedDataTransferItemType<T> => item.type === type,
|
||||||
|
) || null
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const getDataTransferItemData = function <
|
||||||
|
T extends ValueOf<typeof STRING_MIME_TYPES>,
|
||||||
|
>(
|
||||||
|
this: ParsedDataTranferList,
|
||||||
|
type: T,
|
||||||
|
):
|
||||||
|
| ParsedDataTransferItemType<ValueOf<typeof STRING_MIME_TYPES>>["value"]
|
||||||
|
| null {
|
||||||
|
const item = this.find(
|
||||||
|
(
|
||||||
|
item,
|
||||||
|
): item is ParsedDataTransferItemType<ValueOf<typeof STRING_MIME_TYPES>> =>
|
||||||
|
item.type === type,
|
||||||
|
);
|
||||||
|
|
||||||
|
return item?.value ?? null;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getDataTransferFiles = function (
|
||||||
|
this: ParsedDataTranferList,
|
||||||
|
): ParsedDataTransferFile[] {
|
||||||
|
return this.filter(
|
||||||
|
(item): item is ParsedDataTransferFile => item.kind === "file",
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseDataTransferEvent = async (
|
||||||
|
event: ClipboardEvent | DragEvent | React.DragEvent<HTMLDivElement>,
|
||||||
|
): Promise<ParsedDataTranferList> => {
|
||||||
|
let items: DataTransferItemList | undefined = undefined;
|
||||||
|
|
||||||
|
if (isClipboardEvent(event)) {
|
||||||
|
items = event.clipboardData?.items;
|
||||||
|
} else {
|
||||||
|
const dragEvent = event;
|
||||||
|
items = dragEvent.dataTransfer?.items;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataItems = (
|
||||||
|
await Promise.all(
|
||||||
|
Array.from(items || []).map(
|
||||||
|
async (item): Promise<ParsedDataTransferItem | null> => {
|
||||||
|
if (item.kind === "file") {
|
||||||
|
const file = item.getAsFile();
|
||||||
|
if (file) {
|
||||||
|
const fileHandle = await getFileHandle(item);
|
||||||
|
return {
|
||||||
|
type: file.type,
|
||||||
|
kind: "file",
|
||||||
|
file: await normalizeFile(file),
|
||||||
|
fileHandle,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (item.kind === "string") {
|
||||||
|
const { type } = item;
|
||||||
|
let value: string;
|
||||||
|
if ("clipboardData" in event && event.clipboardData) {
|
||||||
|
value = event.clipboardData?.getData(type);
|
||||||
|
} else {
|
||||||
|
value = await new Promise<string>((resolve) => {
|
||||||
|
item.getAsString((str) => resolve(str));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { type, kind: "string", value };
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
).filter((data): data is ParsedDataTransferItem => data != null);
|
||||||
|
|
||||||
|
return Object.assign(dataItems, {
|
||||||
|
findByType: findDataTransferItemType,
|
||||||
|
getData: getDataTransferItemData,
|
||||||
|
getFiles: getDataTransferFiles,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to parse clipboard event.
|
* Attempts to parse clipboard event.
|
||||||
*/
|
*/
|
||||||
export const parseClipboard = async (
|
export const parseClipboard = async (
|
||||||
event: ClipboardEvent,
|
dataList: ParsedDataTranferList,
|
||||||
isPlainPaste = false,
|
isPlainPaste = false,
|
||||||
): Promise<ClipboardData> => {
|
): Promise<ClipboardData> => {
|
||||||
const parsedEventData = await parseClipboardEventTextData(
|
const parsedEventData = await parseClipboardEventTextData(
|
||||||
event,
|
dataList,
|
||||||
isPlainPaste,
|
isPlainPaste,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -519,3 +663,14 @@ const copyTextViaExecCommand = (text: string | null) => {
|
|||||||
|
|
||||||
return success;
|
return success;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isClipboardEvent = (
|
||||||
|
event: React.SyntheticEvent | Event,
|
||||||
|
): event is ClipboardEvent => {
|
||||||
|
/** not using instanceof ClipboardEvent due to tests (jsdom) */
|
||||||
|
return (
|
||||||
|
event.type === EVENT.PASTE ||
|
||||||
|
event.type === EVENT.COPY ||
|
||||||
|
event.type === EVENT.CUT
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@ -91,3 +91,120 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.compact-shape-actions {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
max-height: calc(100vh - 200px);
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0.5rem;
|
||||||
|
|
||||||
|
.compact-action-item {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
min-height: 2.5rem;
|
||||||
|
|
||||||
|
--default-button-size: 2rem;
|
||||||
|
|
||||||
|
.compact-action-button {
|
||||||
|
width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: var(--border-radius-lg);
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-on-surface);
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 1rem;
|
||||||
|
height: 1rem;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: var(--button-hover-bg, var(--island-bg-color));
|
||||||
|
border-color: var(
|
||||||
|
--button-hover-border,
|
||||||
|
var(--button-border, var(--default-border-color))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: var(--button-active-bg, var(--island-bg-color));
|
||||||
|
border-color: var(--button-active-border, var(--color-primary-darkest));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-popover-content {
|
||||||
|
.popover-section {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popover-section-title {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonList {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-shape-actions-island {
|
||||||
|
width: fit-content;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.compact-popover-content {
|
||||||
|
.popover-section {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popover-section-title {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonList {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.shape-actions-theme-scope {
|
||||||
|
--button-border: transparent;
|
||||||
|
--button-bg: var(--color-surface-mid);
|
||||||
|
}
|
||||||
|
|
||||||
|
:root.theme--dark .shape-actions-theme-scope {
|
||||||
|
--button-hover-bg: #363541;
|
||||||
|
--button-bg: var(--color-surface-high);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import * as Popover from "@radix-ui/react-popover";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CLASSES,
|
CLASSES,
|
||||||
@ -19,6 +20,7 @@ import {
|
|||||||
isImageElement,
|
isImageElement,
|
||||||
isLinearElement,
|
isLinearElement,
|
||||||
isTextElement,
|
isTextElement,
|
||||||
|
isArrowElement,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element";
|
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element";
|
||||||
@ -46,15 +48,20 @@ import {
|
|||||||
hasStrokeWidth,
|
hasStrokeWidth,
|
||||||
} from "../scene";
|
} from "../scene";
|
||||||
|
|
||||||
|
import { getFormValue } from "../actions/actionProperties";
|
||||||
|
|
||||||
|
import { useTextEditorFocus } from "../hooks/useTextEditorFocus";
|
||||||
|
|
||||||
import { getToolbarTools } from "./shapes";
|
import { getToolbarTools } from "./shapes";
|
||||||
|
|
||||||
import "./Actions.scss";
|
import "./Actions.scss";
|
||||||
|
|
||||||
import { useDevice } from "./App";
|
import { useDevice, useExcalidrawContainer } from "./App";
|
||||||
import Stack from "./Stack";
|
import Stack from "./Stack";
|
||||||
import { ToolButton } from "./ToolButton";
|
import { ToolButton } from "./ToolButton";
|
||||||
import { Tooltip } from "./Tooltip";
|
import { Tooltip } from "./Tooltip";
|
||||||
import DropdownMenu from "./dropdownMenu/DropdownMenu";
|
import DropdownMenu from "./dropdownMenu/DropdownMenu";
|
||||||
|
import { PropertiesPopover } from "./PropertiesPopover";
|
||||||
import {
|
import {
|
||||||
EmbedIcon,
|
EmbedIcon,
|
||||||
extraToolsIcon,
|
extraToolsIcon,
|
||||||
@ -63,11 +70,29 @@ import {
|
|||||||
laserPointerToolIcon,
|
laserPointerToolIcon,
|
||||||
MagicIcon,
|
MagicIcon,
|
||||||
LassoIcon,
|
LassoIcon,
|
||||||
|
sharpArrowIcon,
|
||||||
|
roundArrowIcon,
|
||||||
|
elbowArrowIcon,
|
||||||
|
TextSizeIcon,
|
||||||
|
adjustmentsIcon,
|
||||||
|
DotsHorizontalIcon,
|
||||||
} from "./icons";
|
} from "./icons";
|
||||||
|
|
||||||
import type { AppClassProperties, AppProps, UIAppState, Zoom } from "../types";
|
import type {
|
||||||
|
AppClassProperties,
|
||||||
|
AppProps,
|
||||||
|
UIAppState,
|
||||||
|
Zoom,
|
||||||
|
AppState,
|
||||||
|
} from "../types";
|
||||||
import type { ActionManager } from "../actions/manager";
|
import type { ActionManager } from "../actions/manager";
|
||||||
|
|
||||||
|
// Common CSS class combinations
|
||||||
|
const PROPERTIES_CLASSES = clsx([
|
||||||
|
CLASSES.SHAPE_ACTIONS_THEME_SCOPE,
|
||||||
|
"properties-content",
|
||||||
|
]);
|
||||||
|
|
||||||
export const canChangeStrokeColor = (
|
export const canChangeStrokeColor = (
|
||||||
appState: UIAppState,
|
appState: UIAppState,
|
||||||
targetElements: ExcalidrawElement[],
|
targetElements: ExcalidrawElement[],
|
||||||
@ -280,6 +305,437 @@ export const SelectedShapeActions = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const CompactShapeActions = ({
|
||||||
|
appState,
|
||||||
|
elementsMap,
|
||||||
|
renderAction,
|
||||||
|
app,
|
||||||
|
setAppState,
|
||||||
|
}: {
|
||||||
|
appState: UIAppState;
|
||||||
|
elementsMap: NonDeletedElementsMap | NonDeletedSceneElementsMap;
|
||||||
|
renderAction: ActionManager["renderAction"];
|
||||||
|
app: AppClassProperties;
|
||||||
|
setAppState: React.Component<any, AppState>["setState"];
|
||||||
|
}) => {
|
||||||
|
const targetElements = getTargetElements(elementsMap, appState);
|
||||||
|
const { saveCaretPosition, restoreCaretPosition } = useTextEditorFocus();
|
||||||
|
const { container } = useExcalidrawContainer();
|
||||||
|
|
||||||
|
const isEditingTextOrNewElement = Boolean(
|
||||||
|
appState.editingTextElement || appState.newElement,
|
||||||
|
);
|
||||||
|
|
||||||
|
const showFillIcons =
|
||||||
|
(hasBackground(appState.activeTool.type) &&
|
||||||
|
!isTransparent(appState.currentItemBackgroundColor)) ||
|
||||||
|
targetElements.some(
|
||||||
|
(element) =>
|
||||||
|
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
||||||
|
);
|
||||||
|
|
||||||
|
const showLinkIcon = targetElements.length === 1;
|
||||||
|
|
||||||
|
const showLineEditorAction =
|
||||||
|
!appState.selectedLinearElement?.isEditing &&
|
||||||
|
targetElements.length === 1 &&
|
||||||
|
isLinearElement(targetElements[0]) &&
|
||||||
|
!isElbowArrow(targetElements[0]);
|
||||||
|
|
||||||
|
const showCropEditorAction =
|
||||||
|
!appState.croppingElementId &&
|
||||||
|
targetElements.length === 1 &&
|
||||||
|
isImageElement(targetElements[0]);
|
||||||
|
|
||||||
|
const showAlignActions = alignActionsPredicate(appState, app);
|
||||||
|
|
||||||
|
let isSingleElementBoundContainer = false;
|
||||||
|
if (
|
||||||
|
targetElements.length === 2 &&
|
||||||
|
(hasBoundTextElement(targetElements[0]) ||
|
||||||
|
hasBoundTextElement(targetElements[1]))
|
||||||
|
) {
|
||||||
|
isSingleElementBoundContainer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isRTL = document.documentElement.getAttribute("dir") === "rtl";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="compact-shape-actions">
|
||||||
|
{/* Stroke Color */}
|
||||||
|
{canChangeStrokeColor(appState, targetElements) && (
|
||||||
|
<div className={clsx("compact-action-item")}>
|
||||||
|
{renderAction("changeStrokeColor")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Background Color */}
|
||||||
|
{canChangeBackgroundColor(appState, targetElements) && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
{renderAction("changeBackgroundColor")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Combined Properties (Fill, Stroke, Opacity) */}
|
||||||
|
{(showFillIcons ||
|
||||||
|
hasStrokeWidth(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) => hasStrokeWidth(element.type)) ||
|
||||||
|
hasStrokeStyle(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) => hasStrokeStyle(element.type)) ||
|
||||||
|
canChangeRoundness(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) => canChangeRoundness(element.type))) && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
<Popover.Root
|
||||||
|
open={appState.openPopup === "compactStrokeStyles"}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (open) {
|
||||||
|
setAppState({ openPopup: "compactStrokeStyles" });
|
||||||
|
} else {
|
||||||
|
setAppState({ openPopup: null });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Popover.Trigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="compact-action-button properties-trigger"
|
||||||
|
title={t("labels.stroke")}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
setAppState({
|
||||||
|
openPopup:
|
||||||
|
appState.openPopup === "compactStrokeStyles"
|
||||||
|
? null
|
||||||
|
: "compactStrokeStyles",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{adjustmentsIcon}
|
||||||
|
</button>
|
||||||
|
</Popover.Trigger>
|
||||||
|
{appState.openPopup === "compactStrokeStyles" && (
|
||||||
|
<PropertiesPopover
|
||||||
|
className={PROPERTIES_CLASSES}
|
||||||
|
container={container}
|
||||||
|
style={{ maxWidth: "13rem" }}
|
||||||
|
onClose={() => {}}
|
||||||
|
>
|
||||||
|
<div className="selected-shape-actions">
|
||||||
|
{showFillIcons && renderAction("changeFillStyle")}
|
||||||
|
{(hasStrokeWidth(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) =>
|
||||||
|
hasStrokeWidth(element.type),
|
||||||
|
)) &&
|
||||||
|
renderAction("changeStrokeWidth")}
|
||||||
|
{(hasStrokeStyle(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) =>
|
||||||
|
hasStrokeStyle(element.type),
|
||||||
|
)) && (
|
||||||
|
<>
|
||||||
|
{renderAction("changeStrokeStyle")}
|
||||||
|
{renderAction("changeSloppiness")}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{(canChangeRoundness(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) =>
|
||||||
|
canChangeRoundness(element.type),
|
||||||
|
)) &&
|
||||||
|
renderAction("changeRoundness")}
|
||||||
|
{renderAction("changeOpacity")}
|
||||||
|
</div>
|
||||||
|
</PropertiesPopover>
|
||||||
|
)}
|
||||||
|
</Popover.Root>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Combined Arrow Properties */}
|
||||||
|
{(toolIsArrow(appState.activeTool.type) ||
|
||||||
|
targetElements.some((element) => toolIsArrow(element.type))) && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
<Popover.Root
|
||||||
|
open={appState.openPopup === "compactArrowProperties"}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (open) {
|
||||||
|
setAppState({ openPopup: "compactArrowProperties" });
|
||||||
|
} else {
|
||||||
|
setAppState({ openPopup: null });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Popover.Trigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="compact-action-button properties-trigger"
|
||||||
|
title={t("labels.arrowtypes")}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
setAppState({
|
||||||
|
openPopup:
|
||||||
|
appState.openPopup === "compactArrowProperties"
|
||||||
|
? null
|
||||||
|
: "compactArrowProperties",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(() => {
|
||||||
|
// Show an icon based on the current arrow type
|
||||||
|
const arrowType = getFormValue(
|
||||||
|
targetElements,
|
||||||
|
app,
|
||||||
|
(element) => {
|
||||||
|
if (isArrowElement(element)) {
|
||||||
|
return element.elbowed
|
||||||
|
? "elbow"
|
||||||
|
: element.roundness
|
||||||
|
? "round"
|
||||||
|
: "sharp";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
(element) => isArrowElement(element),
|
||||||
|
(hasSelection) =>
|
||||||
|
hasSelection ? null : appState.currentItemArrowType,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (arrowType === "elbow") {
|
||||||
|
return elbowArrowIcon;
|
||||||
|
}
|
||||||
|
if (arrowType === "round") {
|
||||||
|
return roundArrowIcon;
|
||||||
|
}
|
||||||
|
return sharpArrowIcon;
|
||||||
|
})()}
|
||||||
|
</button>
|
||||||
|
</Popover.Trigger>
|
||||||
|
{appState.openPopup === "compactArrowProperties" && (
|
||||||
|
<PropertiesPopover
|
||||||
|
container={container}
|
||||||
|
className="properties-content"
|
||||||
|
style={{ maxWidth: "13rem" }}
|
||||||
|
onClose={() => {}}
|
||||||
|
>
|
||||||
|
{renderAction("changeArrowProperties")}
|
||||||
|
</PropertiesPopover>
|
||||||
|
)}
|
||||||
|
</Popover.Root>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Linear Editor */}
|
||||||
|
{showLineEditorAction && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
{renderAction("toggleLinearEditor")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Text Properties */}
|
||||||
|
{(appState.activeTool.type === "text" ||
|
||||||
|
targetElements.some(isTextElement)) && (
|
||||||
|
<>
|
||||||
|
<div className="compact-action-item">
|
||||||
|
{renderAction("changeFontFamily")}
|
||||||
|
</div>
|
||||||
|
<div className="compact-action-item">
|
||||||
|
<Popover.Root
|
||||||
|
open={appState.openPopup === "compactTextProperties"}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (open) {
|
||||||
|
if (appState.editingTextElement) {
|
||||||
|
saveCaretPosition();
|
||||||
|
}
|
||||||
|
setAppState({ openPopup: "compactTextProperties" });
|
||||||
|
} else {
|
||||||
|
setAppState({ openPopup: null });
|
||||||
|
if (appState.editingTextElement) {
|
||||||
|
restoreCaretPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Popover.Trigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="compact-action-button properties-trigger"
|
||||||
|
title={t("labels.textAlign")}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
if (appState.openPopup === "compactTextProperties") {
|
||||||
|
setAppState({ openPopup: null });
|
||||||
|
} else {
|
||||||
|
if (appState.editingTextElement) {
|
||||||
|
saveCaretPosition();
|
||||||
|
}
|
||||||
|
setAppState({ openPopup: "compactTextProperties" });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{TextSizeIcon}
|
||||||
|
</button>
|
||||||
|
</Popover.Trigger>
|
||||||
|
{appState.openPopup === "compactTextProperties" && (
|
||||||
|
<PropertiesPopover
|
||||||
|
className={PROPERTIES_CLASSES}
|
||||||
|
container={container}
|
||||||
|
style={{ maxWidth: "13rem" }}
|
||||||
|
// Improve focus handling for text editing scenarios
|
||||||
|
preventAutoFocusOnTouch={!!appState.editingTextElement}
|
||||||
|
onClose={() => {
|
||||||
|
// Refocus text editor when popover closes with caret restoration
|
||||||
|
if (appState.editingTextElement) {
|
||||||
|
restoreCaretPosition();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="selected-shape-actions">
|
||||||
|
{(appState.activeTool.type === "text" ||
|
||||||
|
targetElements.some(isTextElement)) &&
|
||||||
|
renderAction("changeFontSize")}
|
||||||
|
{(appState.activeTool.type === "text" ||
|
||||||
|
suppportsHorizontalAlign(targetElements, elementsMap)) &&
|
||||||
|
renderAction("changeTextAlign")}
|
||||||
|
{shouldAllowVerticalAlign(targetElements, elementsMap) &&
|
||||||
|
renderAction("changeVerticalAlign")}
|
||||||
|
</div>
|
||||||
|
</PropertiesPopover>
|
||||||
|
)}
|
||||||
|
</Popover.Root>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Dedicated Copy Button */}
|
||||||
|
{!isEditingTextOrNewElement && targetElements.length > 0 && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
{renderAction("duplicateSelection")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Dedicated Delete Button */}
|
||||||
|
{!isEditingTextOrNewElement && targetElements.length > 0 && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
{renderAction("deleteSelectedElements")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Combined Other Actions */}
|
||||||
|
{!isEditingTextOrNewElement && targetElements.length > 0 && (
|
||||||
|
<div className="compact-action-item">
|
||||||
|
<Popover.Root
|
||||||
|
open={appState.openPopup === "compactOtherProperties"}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (open) {
|
||||||
|
setAppState({ openPopup: "compactOtherProperties" });
|
||||||
|
} else {
|
||||||
|
setAppState({ openPopup: null });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Popover.Trigger asChild>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="compact-action-button properties-trigger"
|
||||||
|
title={t("labels.actions")}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
setAppState({
|
||||||
|
openPopup:
|
||||||
|
appState.openPopup === "compactOtherProperties"
|
||||||
|
? null
|
||||||
|
: "compactOtherProperties",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{DotsHorizontalIcon}
|
||||||
|
</button>
|
||||||
|
</Popover.Trigger>
|
||||||
|
{appState.openPopup === "compactOtherProperties" && (
|
||||||
|
<PropertiesPopover
|
||||||
|
className={PROPERTIES_CLASSES}
|
||||||
|
container={container}
|
||||||
|
style={{
|
||||||
|
maxWidth: "12rem",
|
||||||
|
// center the popover content
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
}}
|
||||||
|
onClose={() => {}}
|
||||||
|
>
|
||||||
|
<div className="selected-shape-actions">
|
||||||
|
<fieldset>
|
||||||
|
<legend>{t("labels.layers")}</legend>
|
||||||
|
<div className="buttonList">
|
||||||
|
{renderAction("sendToBack")}
|
||||||
|
{renderAction("sendBackward")}
|
||||||
|
{renderAction("bringForward")}
|
||||||
|
{renderAction("bringToFront")}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
{showAlignActions && !isSingleElementBoundContainer && (
|
||||||
|
<fieldset>
|
||||||
|
<legend>{t("labels.align")}</legend>
|
||||||
|
<div className="buttonList">
|
||||||
|
{isRTL ? (
|
||||||
|
<>
|
||||||
|
{renderAction("alignRight")}
|
||||||
|
{renderAction("alignHorizontallyCentered")}
|
||||||
|
{renderAction("alignLeft")}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{renderAction("alignLeft")}
|
||||||
|
{renderAction("alignHorizontallyCentered")}
|
||||||
|
{renderAction("alignRight")}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{targetElements.length > 2 &&
|
||||||
|
renderAction("distributeHorizontally")}
|
||||||
|
{/* breaks the row ˇˇ */}
|
||||||
|
<div style={{ flexBasis: "100%", height: 0 }} />
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
gap: ".5rem",
|
||||||
|
marginTop: "-0.5rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{renderAction("alignTop")}
|
||||||
|
{renderAction("alignVerticallyCentered")}
|
||||||
|
{renderAction("alignBottom")}
|
||||||
|
{targetElements.length > 2 &&
|
||||||
|
renderAction("distributeVertically")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
)}
|
||||||
|
<fieldset>
|
||||||
|
<legend>{t("labels.actions")}</legend>
|
||||||
|
<div className="buttonList">
|
||||||
|
{renderAction("group")}
|
||||||
|
{renderAction("ungroup")}
|
||||||
|
{showLinkIcon && renderAction("hyperlink")}
|
||||||
|
{showCropEditorAction && renderAction("cropEditor")}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</PropertiesPopover>
|
||||||
|
)}
|
||||||
|
</Popover.Root>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const ShapesSwitcher = ({
|
export const ShapesSwitcher = ({
|
||||||
activeTool,
|
activeTool,
|
||||||
appState,
|
appState,
|
||||||
@ -397,7 +853,6 @@ export const ShapesSwitcher = ({
|
|||||||
onClickOutside={() => setIsExtraToolsMenuOpen(false)}
|
onClickOutside={() => setIsExtraToolsMenuOpen(false)}
|
||||||
onSelect={() => setIsExtraToolsMenuOpen(false)}
|
onSelect={() => setIsExtraToolsMenuOpen(false)}
|
||||||
className="App-toolbar__extra-tools-dropdown"
|
className="App-toolbar__extra-tools-dropdown"
|
||||||
align="end"
|
|
||||||
>
|
>
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
onSelect={() => app.setActiveTool({ type: "frame" })}
|
onSelect={() => app.setActiveTool({ type: "frame" })}
|
||||||
@ -451,10 +906,10 @@ export const ShapesSwitcher = ({
|
|||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
onSelect={() => app.onMagicframeToolSelect()}
|
onSelect={() => app.onMagicframeToolSelect()}
|
||||||
icon={MagicIcon}
|
icon={MagicIcon}
|
||||||
badge={<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>}
|
|
||||||
data-testid="toolbar-magicframe"
|
data-testid="toolbar-magicframe"
|
||||||
>
|
>
|
||||||
{t("toolBar.magicframe")}
|
{t("toolBar.magicframe")}
|
||||||
|
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -41,9 +41,6 @@ import {
|
|||||||
LINE_CONFIRM_THRESHOLD,
|
LINE_CONFIRM_THRESHOLD,
|
||||||
MAX_ALLOWED_FILE_BYTES,
|
MAX_ALLOWED_FILE_BYTES,
|
||||||
MIME_TYPES,
|
MIME_TYPES,
|
||||||
MQ_MAX_HEIGHT_LANDSCAPE,
|
|
||||||
MQ_MAX_WIDTH_LANDSCAPE,
|
|
||||||
MQ_MAX_WIDTH_PORTRAIT,
|
|
||||||
MQ_RIGHT_SIDEBAR_MIN_WIDTH,
|
MQ_RIGHT_SIDEBAR_MIN_WIDTH,
|
||||||
POINTER_BUTTON,
|
POINTER_BUTTON,
|
||||||
ROUNDNESS,
|
ROUNDNESS,
|
||||||
@ -100,9 +97,12 @@ import {
|
|||||||
randomInteger,
|
randomInteger,
|
||||||
CLASSES,
|
CLASSES,
|
||||||
Emitter,
|
Emitter,
|
||||||
isMobile,
|
|
||||||
MINIMUM_ARROW_SIZE,
|
MINIMUM_ARROW_SIZE,
|
||||||
DOUBLE_TAP_POSITION_THRESHOLD,
|
DOUBLE_TAP_POSITION_THRESHOLD,
|
||||||
|
isMobileOrTablet,
|
||||||
|
MQ_MAX_MOBILE,
|
||||||
|
MQ_MIN_TABLET,
|
||||||
|
MQ_MAX_TABLET,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -237,6 +237,7 @@ import {
|
|||||||
isSimpleArrow,
|
isSimpleArrow,
|
||||||
StoreDelta,
|
StoreDelta,
|
||||||
type ApplyToOptions,
|
type ApplyToOptions,
|
||||||
|
positionElementsOnGrid,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
|
|
||||||
import type { LocalPoint, Radians } from "@excalidraw/math";
|
import type { LocalPoint, Radians } from "@excalidraw/math";
|
||||||
@ -323,7 +324,13 @@ import {
|
|||||||
isEraserActive,
|
isEraserActive,
|
||||||
isHandToolActive,
|
isHandToolActive,
|
||||||
} from "../appState";
|
} from "../appState";
|
||||||
import { copyTextToSystemClipboard, parseClipboard } from "../clipboard";
|
import {
|
||||||
|
copyTextToSystemClipboard,
|
||||||
|
parseClipboard,
|
||||||
|
parseDataTransferEvent,
|
||||||
|
type ParsedDataTransferFile,
|
||||||
|
} from "../clipboard";
|
||||||
|
|
||||||
import { exportCanvas, loadFromBlob } from "../data";
|
import { exportCanvas, loadFromBlob } from "../data";
|
||||||
import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
import Library, { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
||||||
import { restore, restoreElements } from "../data/restore";
|
import { restore, restoreElements } from "../data/restore";
|
||||||
@ -345,7 +352,6 @@ import {
|
|||||||
generateIdFromFile,
|
generateIdFromFile,
|
||||||
getDataURL,
|
getDataURL,
|
||||||
getDataURL_sync,
|
getDataURL_sync,
|
||||||
getFileFromEvent,
|
|
||||||
ImageURLToFile,
|
ImageURLToFile,
|
||||||
isImageFileHandle,
|
isImageFileHandle,
|
||||||
isSupportedImageFile,
|
isSupportedImageFile,
|
||||||
@ -432,7 +438,7 @@ import type {
|
|||||||
ScrollBars,
|
ScrollBars,
|
||||||
} from "../scene/types";
|
} from "../scene/types";
|
||||||
|
|
||||||
import type { PastedMixedContent } from "../clipboard";
|
import type { ClipboardData, PastedMixedContent } from "../clipboard";
|
||||||
import type { ExportedElements } from "../data";
|
import type { ExportedElements } from "../data";
|
||||||
import type { ContextMenuItems } from "./ContextMenu";
|
import type { ContextMenuItems } from "./ContextMenu";
|
||||||
import type { FileSystemHandle } from "../data/filesystem";
|
import type { FileSystemHandle } from "../data/filesystem";
|
||||||
@ -661,7 +667,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
constructor(props: AppProps) {
|
constructor(props: AppProps) {
|
||||||
super(props);
|
super(props);
|
||||||
const defaultAppState = getDefaultAppState();
|
const defaultAppState = getDefaultAppState();
|
||||||
this.defaultSelectionTool = this.isMobileOrTablet()
|
this.defaultSelectionTool = isMobileOrTablet()
|
||||||
? ("lasso" as const)
|
? ("lasso" as const)
|
||||||
: ("selection" as const);
|
: ("selection" as const);
|
||||||
const {
|
const {
|
||||||
@ -2414,21 +2420,16 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private isMobileOrTablet = (): boolean => {
|
private isMobileBreakpoint = (width: number, height: number) => {
|
||||||
const hasTouch = "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
const minSide = Math.min(width, height);
|
||||||
const hasCoarsePointer =
|
return minSide <= MQ_MAX_MOBILE;
|
||||||
"matchMedia" in window &&
|
|
||||||
window?.matchMedia("(pointer: coarse)")?.matches;
|
|
||||||
const isTouchMobile = hasTouch && hasCoarsePointer;
|
|
||||||
|
|
||||||
return isMobile || isTouchMobile;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private isMobileBreakpoint = (width: number, height: number) => {
|
private isTabletBreakpoint = (editorWidth: number, editorHeight: number) => {
|
||||||
return (
|
const minSide = Math.min(editorWidth, editorHeight);
|
||||||
width < MQ_MAX_WIDTH_PORTRAIT ||
|
const maxSide = Math.max(editorWidth, editorHeight);
|
||||||
(height < MQ_MAX_HEIGHT_LANDSCAPE && width < MQ_MAX_WIDTH_LANDSCAPE)
|
|
||||||
);
|
return minSide >= MQ_MIN_TABLET && maxSide <= MQ_MAX_TABLET;
|
||||||
};
|
};
|
||||||
|
|
||||||
private refreshViewportBreakpoints = () => {
|
private refreshViewportBreakpoints = () => {
|
||||||
@ -2437,14 +2438,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { clientWidth: viewportWidth, clientHeight: viewportHeight } =
|
const { width: editorWidth, height: editorHeight } =
|
||||||
document.body;
|
container.getBoundingClientRect();
|
||||||
|
|
||||||
const prevViewportState = this.device.viewport;
|
const prevViewportState = this.device.viewport;
|
||||||
|
|
||||||
const nextViewportState = updateObject(prevViewportState, {
|
const nextViewportState = updateObject(prevViewportState, {
|
||||||
isLandscape: viewportWidth > viewportHeight,
|
isLandscape: editorWidth > editorHeight,
|
||||||
isMobile: this.isMobileBreakpoint(viewportWidth, viewportHeight),
|
isMobile: this.isMobileBreakpoint(editorWidth, editorHeight),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (prevViewportState !== nextViewportState) {
|
if (prevViewportState !== nextViewportState) {
|
||||||
@ -2475,6 +2476,17 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
canFitSidebar: editorWidth > sidebarBreakpoint,
|
canFitSidebar: editorWidth > sidebarBreakpoint,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// also check if we need to update the app state
|
||||||
|
this.setState({
|
||||||
|
stylesPanelMode:
|
||||||
|
// NOTE: we could also remove the isMobileOrTablet check here and
|
||||||
|
// always switch to compact mode when the editor is narrow (e.g. < MQ_MIN_WIDTH_DESKTOP)
|
||||||
|
// but not too narrow (> MQ_MAX_WIDTH_MOBILE)
|
||||||
|
this.isTabletBreakpoint(editorWidth, editorHeight) && isMobileOrTablet()
|
||||||
|
? "compact"
|
||||||
|
: "full",
|
||||||
|
});
|
||||||
|
|
||||||
if (prevEditorState !== nextEditorState) {
|
if (prevEditorState !== nextEditorState) {
|
||||||
this.device = { ...this.device, editor: nextEditorState };
|
this.device = { ...this.device, editor: nextEditorState };
|
||||||
return true;
|
return true;
|
||||||
@ -3066,31 +3078,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: this is so spaghetti, we should refactor it and cover it with tests
|
// TODO: Cover with tests
|
||||||
public pasteFromClipboard = withBatchedUpdates(
|
private async insertClipboardContent(
|
||||||
async (event: ClipboardEvent) => {
|
data: ClipboardData,
|
||||||
const isPlainPaste = !!IS_PLAIN_PASTE;
|
dataTransferFiles: ParsedDataTransferFile[],
|
||||||
|
isPlainPaste: boolean,
|
||||||
// #686
|
|
||||||
const target = document.activeElement;
|
|
||||||
const isExcalidrawActive =
|
|
||||||
this.excalidrawContainerRef.current?.contains(target);
|
|
||||||
if (event && !isExcalidrawActive) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const elementUnderCursor = document.elementFromPoint(
|
|
||||||
this.lastViewportPosition.x,
|
|
||||||
this.lastViewportPosition.y,
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
event &&
|
|
||||||
(!(elementUnderCursor instanceof HTMLCanvasElement) ||
|
|
||||||
isWritableElement(target))
|
|
||||||
) {
|
) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { x: sceneX, y: sceneY } = viewportCoordsToSceneCoords(
|
const { x: sceneX, y: sceneY } = viewportCoordsToSceneCoords(
|
||||||
{
|
{
|
||||||
clientX: this.lastViewportPosition.x,
|
clientX: this.lastViewportPosition.x,
|
||||||
@ -3099,60 +3092,56 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.state,
|
this.state,
|
||||||
);
|
);
|
||||||
|
|
||||||
// must be called in the same frame (thus before any awaits) as the paste
|
// ------------------- Error -------------------
|
||||||
// event else some browsers (FF...) will clear the clipboardData
|
if (data.errorMessage) {
|
||||||
// (something something security)
|
this.setState({ errorMessage: data.errorMessage });
|
||||||
let file = event?.clipboardData?.files[0];
|
return;
|
||||||
const data = await parseClipboard(event, isPlainPaste);
|
}
|
||||||
if (!file && !isPlainPaste) {
|
|
||||||
if (data.mixedContent) {
|
// ------------------- Mixed content with no files -------------------
|
||||||
return this.addElementsFromMixedContentPaste(data.mixedContent, {
|
if (dataTransferFiles.length === 0 && !isPlainPaste && data.mixedContent) {
|
||||||
|
await this.addElementsFromMixedContentPaste(data.mixedContent, {
|
||||||
isPlainPaste,
|
isPlainPaste,
|
||||||
sceneX,
|
sceneX,
|
||||||
sceneY,
|
sceneY,
|
||||||
});
|
});
|
||||||
} else if (data.text) {
|
|
||||||
const string = data.text.trim();
|
|
||||||
if (string.startsWith("<svg") && string.endsWith("</svg>")) {
|
|
||||||
// ignore SVG validation/normalization which will be done during image
|
|
||||||
// initialization
|
|
||||||
file = SVGStringToFile(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// prefer spreadsheet data over image file (MS Office/Libre Office)
|
|
||||||
if (isSupportedImageFile(file) && !data.spreadsheet) {
|
|
||||||
if (!this.isToolSupported("image")) {
|
|
||||||
this.setState({ errorMessage: t("errors.imageToolNotSupported") });
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createImageElement({ sceneX, sceneY, imageFile: file });
|
// ------------------- Spreadsheet -------------------
|
||||||
|
if (data.spreadsheet && !isPlainPaste) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.props.onPaste) {
|
|
||||||
try {
|
|
||||||
if ((await this.props.onPaste(data, event)) === false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.errorMessage) {
|
|
||||||
this.setState({ errorMessage: data.errorMessage });
|
|
||||||
} else if (data.spreadsheet && !isPlainPaste) {
|
|
||||||
this.setState({
|
this.setState({
|
||||||
pasteDialog: {
|
pasteDialog: {
|
||||||
data: data.spreadsheet,
|
data: data.spreadsheet,
|
||||||
shown: true,
|
shown: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else if (data.elements) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------- Images or SVG code -------------------
|
||||||
|
const imageFiles = dataTransferFiles.map((data) => data.file);
|
||||||
|
|
||||||
|
if (imageFiles.length === 0 && data.text && !isPlainPaste) {
|
||||||
|
const trimmedText = data.text.trim();
|
||||||
|
if (trimmedText.startsWith("<svg") && trimmedText.endsWith("</svg>")) {
|
||||||
|
// ignore SVG validation/normalization which will be done during image
|
||||||
|
// initialization
|
||||||
|
imageFiles.push(SVGStringToFile(trimmedText));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageFiles.length > 0) {
|
||||||
|
if (this.isToolSupported("image")) {
|
||||||
|
await this.insertImages(imageFiles, sceneX, sceneY);
|
||||||
|
} else {
|
||||||
|
this.setState({ errorMessage: t("errors.imageToolNotSupported") });
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------- Elements -------------------
|
||||||
|
if (data.elements) {
|
||||||
const elements = (
|
const elements = (
|
||||||
data.programmaticAPI
|
data.programmaticAPI
|
||||||
? convertToExcalidrawElements(
|
? convertToExcalidrawElements(
|
||||||
@ -3160,17 +3149,24 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
)
|
)
|
||||||
: data.elements
|
: data.elements
|
||||||
) as readonly ExcalidrawElement[];
|
) as readonly ExcalidrawElement[];
|
||||||
// TODO remove formatting from elements if isPlainPaste
|
// TODO: remove formatting from elements if isPlainPaste
|
||||||
this.addElementsFromPasteOrLibrary({
|
this.addElementsFromPasteOrLibrary({
|
||||||
elements,
|
elements,
|
||||||
files: data.files || null,
|
files: data.files || null,
|
||||||
position: this.isMobileOrTablet() ? "center" : "cursor",
|
position: isMobileOrTablet() ? "center" : "cursor",
|
||||||
retainSeed: isPlainPaste,
|
retainSeed: isPlainPaste,
|
||||||
});
|
});
|
||||||
} else if (data.text) {
|
return;
|
||||||
if (data.text && isMaybeMermaidDefinition(data.text)) {
|
}
|
||||||
const api = await import("@excalidraw/mermaid-to-excalidraw");
|
|
||||||
|
|
||||||
|
// ------------------- Only textual stuff remaining -------------------
|
||||||
|
if (!data.text) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------- Successful Mermaid -------------------
|
||||||
|
if (!isPlainPaste && isMaybeMermaidDefinition(data.text)) {
|
||||||
|
const api = await import("@excalidraw/mermaid-to-excalidraw");
|
||||||
try {
|
try {
|
||||||
const { elements: skeletonElements, files } =
|
const { elements: skeletonElements, files } =
|
||||||
await api.parseMermaidToExcalidraw(data.text);
|
await api.parseMermaidToExcalidraw(data.text);
|
||||||
@ -3182,7 +3178,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.addElementsFromPasteOrLibrary({
|
this.addElementsFromPasteOrLibrary({
|
||||||
elements,
|
elements,
|
||||||
files,
|
files,
|
||||||
position: this.isMobileOrTablet() ? "center" : "cursor",
|
position: isMobileOrTablet() ? "center" : "cursor",
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -3193,26 +3189,23 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------- Pure embeddable URLs -------------------
|
||||||
const nonEmptyLines = normalizeEOL(data.text)
|
const nonEmptyLines = normalizeEOL(data.text)
|
||||||
.split(/\n+/)
|
.split(/\n+/)
|
||||||
.map((s) => s.trim())
|
.map((s) => s.trim())
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
const embbeddableUrls = nonEmptyLines
|
const embbeddableUrls = nonEmptyLines
|
||||||
.map((str) => maybeParseEmbedSrc(str))
|
.map((str) => maybeParseEmbedSrc(str))
|
||||||
.filter((string) => {
|
.filter(
|
||||||
return (
|
(string) =>
|
||||||
embeddableURLValidator(string, this.props.validateEmbeddable) &&
|
embeddableURLValidator(string, this.props.validateEmbeddable) &&
|
||||||
(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(string) ||
|
(/^(http|https):\/\/[^\s/$.?#].[^\s]*$/.test(string) ||
|
||||||
getEmbedLink(string)?.type === "video")
|
getEmbedLink(string)?.type === "video"),
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!IS_PLAIN_PASTE &&
|
!isPlainPaste &&
|
||||||
embbeddableUrls.length > 0 &&
|
embbeddableUrls.length > 0 &&
|
||||||
// if there were non-embeddable text (lines) mixed in with embeddable
|
|
||||||
// urls, ignore and paste as text
|
|
||||||
embbeddableUrls.length === nonEmptyLines.length
|
embbeddableUrls.length === nonEmptyLines.length
|
||||||
) {
|
) {
|
||||||
const embeddables: NonDeleted<ExcalidrawEmbeddableElement>[] = [];
|
const embeddables: NonDeleted<ExcalidrawEmbeddableElement>[] = [];
|
||||||
@ -3240,8 +3233,56 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------- Text -------------------
|
||||||
this.addTextFromPaste(data.text, isPlainPaste);
|
this.addTextFromPaste(data.text, isPlainPaste);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public pasteFromClipboard = withBatchedUpdates(
|
||||||
|
async (event: ClipboardEvent) => {
|
||||||
|
const isPlainPaste = !!IS_PLAIN_PASTE;
|
||||||
|
|
||||||
|
// #686
|
||||||
|
const target = document.activeElement;
|
||||||
|
const isExcalidrawActive =
|
||||||
|
this.excalidrawContainerRef.current?.contains(target);
|
||||||
|
if (event && !isExcalidrawActive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const elementUnderCursor = document.elementFromPoint(
|
||||||
|
this.lastViewportPosition.x,
|
||||||
|
this.lastViewportPosition.y,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
event &&
|
||||||
|
(!(elementUnderCursor instanceof HTMLCanvasElement) ||
|
||||||
|
isWritableElement(target))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// must be called in the same frame (thus before any awaits) as the paste
|
||||||
|
// event else some browsers (FF...) will clear the clipboardData
|
||||||
|
// (something something security)
|
||||||
|
const dataTransferList = await parseDataTransferEvent(event);
|
||||||
|
|
||||||
|
const filesList = dataTransferList.getFiles();
|
||||||
|
|
||||||
|
const data = await parseClipboard(dataTransferList, isPlainPaste);
|
||||||
|
|
||||||
|
if (this.props.onPaste) {
|
||||||
|
try {
|
||||||
|
if ((await this.props.onPaste(data, event)) === false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.insertClipboardContent(data, filesList, isPlainPaste);
|
||||||
|
|
||||||
this.setActiveTool({ type: this.defaultSelectionTool }, true);
|
this.setActiveTool({ type: this.defaultSelectionTool }, true);
|
||||||
event?.preventDefault();
|
event?.preventDefault();
|
||||||
},
|
},
|
||||||
@ -3431,45 +3472,11 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
let y = sceneY;
|
|
||||||
let firstImageYOffsetDone = false;
|
|
||||||
const nextSelectedIds: Record<ExcalidrawElement["id"], true> = {};
|
|
||||||
for (const response of responses) {
|
|
||||||
if (response.file) {
|
|
||||||
const initializedImageElement = await this.createImageElement({
|
|
||||||
sceneX,
|
|
||||||
sceneY: y,
|
|
||||||
imageFile: response.file,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (initializedImageElement) {
|
|
||||||
// vertically center first image in the batch
|
|
||||||
if (!firstImageYOffsetDone) {
|
|
||||||
firstImageYOffsetDone = true;
|
|
||||||
y -= initializedImageElement.height / 2;
|
|
||||||
}
|
|
||||||
// hack to reset the `y` coord because we vertically center during
|
|
||||||
// insertImageElement
|
|
||||||
this.scene.mutateElement(
|
|
||||||
initializedImageElement,
|
|
||||||
{ y },
|
|
||||||
{ informMutation: false, isDragging: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
y = initializedImageElement.y + initializedImageElement.height + 25;
|
|
||||||
|
|
||||||
nextSelectedIds[initializedImageElement.id] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
selectedElementIds: makeNextSelectedElementIds(
|
|
||||||
nextSelectedIds,
|
|
||||||
this.state,
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
|
const imageFiles = responses
|
||||||
|
.filter((response): response is { file: File } => !!response.file)
|
||||||
|
.map((response) => response.file);
|
||||||
|
await this.insertImages(imageFiles, sceneX, sceneY);
|
||||||
const error = responses.find((response) => !!response.errorMessage);
|
const error = responses.find((response) => !!response.errorMessage);
|
||||||
if (error && error.errorMessage) {
|
if (error && error.errorMessage) {
|
||||||
this.setState({ errorMessage: error.errorMessage });
|
this.setState({ errorMessage: error.errorMessage });
|
||||||
@ -4806,7 +4813,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.setState({ suggestedBindings: [] });
|
this.setState({ suggestedBindings: [] });
|
||||||
}
|
}
|
||||||
if (nextActiveTool.type === "image") {
|
if (nextActiveTool.type === "image") {
|
||||||
this.onImageAction();
|
this.onImageToolbarButtonClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState((prevState) => {
|
this.setState((prevState) => {
|
||||||
@ -6667,8 +6674,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
pointerDownState.hit.element &&
|
pointerDownState.hit.element &&
|
||||||
this.isASelectedElement(pointerDownState.hit.element);
|
this.isASelectedElement(pointerDownState.hit.element);
|
||||||
|
|
||||||
const isMobileOrTablet = this.isMobileOrTablet();
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!pointerDownState.hit.hasHitCommonBoundingBoxOfSelectedElements &&
|
!pointerDownState.hit.hasHitCommonBoundingBoxOfSelectedElements &&
|
||||||
!pointerDownState.resize.handleType &&
|
!pointerDownState.resize.handleType &&
|
||||||
@ -6682,12 +6687,12 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
// block dragging after lasso selection on PCs until the next pointer down
|
// block dragging after lasso selection on PCs until the next pointer down
|
||||||
// (on mobile or tablet, we want to allow user to drag immediately)
|
// (on mobile or tablet, we want to allow user to drag immediately)
|
||||||
pointerDownState.drag.blockDragging = !isMobileOrTablet;
|
pointerDownState.drag.blockDragging = !isMobileOrTablet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// only for mobile or tablet, if we hit an element, select it immediately like normal selection
|
// only for mobile or tablet, if we hit an element, select it immediately like normal selection
|
||||||
if (
|
if (
|
||||||
isMobileOrTablet &&
|
isMobileOrTablet() &&
|
||||||
pointerDownState.hit.element &&
|
pointerDownState.hit.element &&
|
||||||
!hitSelectedElement
|
!hitSelectedElement
|
||||||
) {
|
) {
|
||||||
@ -7243,6 +7248,16 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
selectedElements.length === 1 &&
|
selectedElements.length === 1 &&
|
||||||
!this.state.selectedLinearElement?.isEditing &&
|
!this.state.selectedLinearElement?.isEditing &&
|
||||||
!isElbowArrow(selectedElements[0]) &&
|
!isElbowArrow(selectedElements[0]) &&
|
||||||
|
!(
|
||||||
|
isLineElement(selectedElements[0]) &&
|
||||||
|
LinearElementEditor.getPointIndexUnderCursor(
|
||||||
|
selectedElements[0],
|
||||||
|
elementsMap,
|
||||||
|
this.state.zoom,
|
||||||
|
pointerDownState.origin.x,
|
||||||
|
pointerDownState.origin.y,
|
||||||
|
) !== -1
|
||||||
|
) &&
|
||||||
!(
|
!(
|
||||||
this.state.selectedLinearElement &&
|
this.state.selectedLinearElement &&
|
||||||
this.state.selectedLinearElement.hoverPointIndex !== -1
|
this.state.selectedLinearElement.hoverPointIndex !== -1
|
||||||
@ -7842,16 +7857,14 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
|
||||||
private createImageElement = async ({
|
private newImagePlaceholder = ({
|
||||||
sceneX,
|
sceneX,
|
||||||
sceneY,
|
sceneY,
|
||||||
addToFrameUnderCursor = true,
|
addToFrameUnderCursor = true,
|
||||||
imageFile,
|
|
||||||
}: {
|
}: {
|
||||||
sceneX: number;
|
sceneX: number;
|
||||||
sceneY: number;
|
sceneY: number;
|
||||||
addToFrameUnderCursor?: boolean;
|
addToFrameUnderCursor?: boolean;
|
||||||
imageFile: File;
|
|
||||||
}) => {
|
}) => {
|
||||||
const [gridX, gridY] = getGridPoint(
|
const [gridX, gridY] = getGridPoint(
|
||||||
sceneX,
|
sceneX,
|
||||||
@ -7870,7 +7883,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
const placeholderSize = 100 / this.state.zoom.value;
|
const placeholderSize = 100 / this.state.zoom.value;
|
||||||
|
|
||||||
const placeholderImageElement = newImageElement({
|
return newImageElement({
|
||||||
type: "image",
|
type: "image",
|
||||||
strokeColor: this.state.currentItemStrokeColor,
|
strokeColor: this.state.currentItemStrokeColor,
|
||||||
backgroundColor: this.state.currentItemBackgroundColor,
|
backgroundColor: this.state.currentItemBackgroundColor,
|
||||||
@ -7887,13 +7900,6 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
width: placeholderSize,
|
width: placeholderSize,
|
||||||
height: placeholderSize,
|
height: placeholderSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
const initializedImageElement = await this.insertImageElement(
|
|
||||||
placeholderImageElement,
|
|
||||||
imageFile,
|
|
||||||
);
|
|
||||||
|
|
||||||
return initializedImageElement;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private handleLinearElementOnPointerDown = (
|
private handleLinearElementOnPointerDown = (
|
||||||
@ -8497,7 +8503,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
if (
|
if (
|
||||||
this.state.activeTool.type === "lasso" &&
|
this.state.activeTool.type === "lasso" &&
|
||||||
this.lassoTrail.hasCurrentTrail &&
|
this.lassoTrail.hasCurrentTrail &&
|
||||||
!(this.isMobileOrTablet() && pointerDownState.hit.element) &&
|
!(isMobileOrTablet() && pointerDownState.hit.element) &&
|
||||||
!this.state.activeTool.fromSelection
|
!this.state.activeTool.fromSelection
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
@ -10215,64 +10221,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
private onImageToolbarButtonClick = async () => {
|
||||||
* inserts image into elements array and rerenders
|
|
||||||
*/
|
|
||||||
private insertImageElement = async (
|
|
||||||
placeholderImageElement: ExcalidrawImageElement,
|
|
||||||
imageFile: File,
|
|
||||||
) => {
|
|
||||||
// we should be handling all cases upstream, but in case we forget to handle
|
|
||||||
// a future case, let's throw here
|
|
||||||
if (!this.isToolSupported("image")) {
|
|
||||||
this.setState({ errorMessage: t("errors.imageToolNotSupported") });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.scene.insertElement(placeholderImageElement);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const initializedImageElement = await this.initializeImage(
|
|
||||||
placeholderImageElement,
|
|
||||||
imageFile,
|
|
||||||
);
|
|
||||||
|
|
||||||
const nextElements = this.scene
|
|
||||||
.getElementsIncludingDeleted()
|
|
||||||
.map((element) => {
|
|
||||||
if (element.id === initializedImageElement.id) {
|
|
||||||
return initializedImageElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
return element;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.updateScene({
|
|
||||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
|
||||||
elements: nextElements,
|
|
||||||
appState: {
|
|
||||||
selectedElementIds: makeNextSelectedElementIds(
|
|
||||||
{ [initializedImageElement.id]: true },
|
|
||||||
this.state,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return initializedImageElement;
|
|
||||||
} catch (error: any) {
|
|
||||||
this.store.scheduleAction(CaptureUpdateAction.NEVER);
|
|
||||||
this.scene.mutateElement(placeholderImageElement, {
|
|
||||||
isDeleted: true,
|
|
||||||
});
|
|
||||||
this.actionManager.executeAction(actionFinalize);
|
|
||||||
this.setState({
|
|
||||||
errorMessage: error.message || t("errors.imageInsertError"),
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private onImageAction = async () => {
|
|
||||||
try {
|
try {
|
||||||
const clientX = this.state.width / 2 + this.state.offsetLeft;
|
const clientX = this.state.width / 2 + this.state.offsetLeft;
|
||||||
const clientY = this.state.height / 2 + this.state.offsetTop;
|
const clientY = this.state.height / 2 + this.state.offsetTop;
|
||||||
@ -10282,24 +10231,15 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
this.state,
|
this.state,
|
||||||
);
|
);
|
||||||
|
|
||||||
const imageFile = await fileOpen({
|
const imageFiles = await fileOpen({
|
||||||
description: "Image",
|
description: "Image",
|
||||||
extensions: Object.keys(
|
extensions: Object.keys(
|
||||||
IMAGE_MIME_TYPES,
|
IMAGE_MIME_TYPES,
|
||||||
) as (keyof typeof IMAGE_MIME_TYPES)[],
|
) as (keyof typeof IMAGE_MIME_TYPES)[],
|
||||||
|
multiple: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.createImageElement({
|
this.insertImages(imageFiles, x, y);
|
||||||
sceneX: x,
|
|
||||||
sceneY: y,
|
|
||||||
addToFrameUnderCursor: false,
|
|
||||||
imageFile,
|
|
||||||
});
|
|
||||||
|
|
||||||
// avoid being batched (just in case)
|
|
||||||
this.setState({}, () => {
|
|
||||||
this.actionManager.executeAction(actionFinalize);
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.name !== "AbortError") {
|
if (error.name !== "AbortError") {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -10496,23 +10436,82 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private insertImages = async (
|
||||||
|
imageFiles: File[],
|
||||||
|
sceneX: number,
|
||||||
|
sceneY: number,
|
||||||
|
) => {
|
||||||
|
const gridPadding = 50 / this.state.zoom.value;
|
||||||
|
// Create, position, and insert placeholders
|
||||||
|
const placeholders = positionElementsOnGrid(
|
||||||
|
imageFiles.map(() => this.newImagePlaceholder({ sceneX, sceneY })),
|
||||||
|
sceneX,
|
||||||
|
sceneY,
|
||||||
|
gridPadding,
|
||||||
|
);
|
||||||
|
placeholders.forEach((el) => this.scene.insertElement(el));
|
||||||
|
|
||||||
|
// Create, position, insert and select initialized (replacing placeholders)
|
||||||
|
const initialized = await Promise.all(
|
||||||
|
placeholders.map(async (placeholder, i) => {
|
||||||
|
try {
|
||||||
|
return await this.initializeImage(placeholder, imageFiles[i]);
|
||||||
|
} catch (error: any) {
|
||||||
|
this.setState({
|
||||||
|
errorMessage: error.message || t("errors.imageInsertError"),
|
||||||
|
});
|
||||||
|
return newElementWith(placeholder, { isDeleted: true });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const initializedMap = arrayToMap(initialized);
|
||||||
|
|
||||||
|
const positioned = positionElementsOnGrid(
|
||||||
|
initialized.filter((el) => !el.isDeleted),
|
||||||
|
sceneX,
|
||||||
|
sceneY,
|
||||||
|
gridPadding,
|
||||||
|
);
|
||||||
|
const positionedMap = arrayToMap(positioned);
|
||||||
|
|
||||||
|
const nextElements = this.scene
|
||||||
|
.getElementsIncludingDeleted()
|
||||||
|
.map((el) => positionedMap.get(el.id) ?? initializedMap.get(el.id) ?? el);
|
||||||
|
|
||||||
|
this.updateScene({
|
||||||
|
appState: {
|
||||||
|
selectedElementIds: makeNextSelectedElementIds(
|
||||||
|
Object.fromEntries(positioned.map((el) => [el.id, true])),
|
||||||
|
this.state,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
elements: nextElements,
|
||||||
|
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({}, () => {
|
||||||
|
// actionFinalize after all state values have been updated
|
||||||
|
this.actionManager.executeAction(actionFinalize);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
private handleAppOnDrop = async (event: React.DragEvent<HTMLDivElement>) => {
|
private handleAppOnDrop = async (event: React.DragEvent<HTMLDivElement>) => {
|
||||||
// must be retrieved first, in the same frame
|
|
||||||
const { file, fileHandle } = await getFileFromEvent(event);
|
|
||||||
const { x: sceneX, y: sceneY } = viewportCoordsToSceneCoords(
|
const { x: sceneX, y: sceneY } = viewportCoordsToSceneCoords(
|
||||||
event,
|
event,
|
||||||
this.state,
|
this.state,
|
||||||
);
|
);
|
||||||
|
const dataTransferList = await parseDataTransferEvent(event);
|
||||||
|
|
||||||
try {
|
// must be retrieved first, in the same frame
|
||||||
// if image tool not supported, don't show an error here and let it fall
|
const fileItems = dataTransferList.getFiles();
|
||||||
// through so we still support importing scene data from images. If no
|
|
||||||
// scene data encoded, we'll show an error then
|
|
||||||
if (isSupportedImageFile(file) && this.isToolSupported("image")) {
|
|
||||||
// first attempt to decode scene from the image if it's embedded
|
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
if (file?.type === MIME_TYPES.png || file?.type === MIME_TYPES.svg) {
|
if (fileItems.length === 1) {
|
||||||
|
const { file, fileHandle } = fileItems[0];
|
||||||
|
|
||||||
|
if (
|
||||||
|
file &&
|
||||||
|
(file.type === MIME_TYPES.png || file.type === MIME_TYPES.svg)
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const scene = await loadFromBlob(
|
const scene = await loadFromBlob(
|
||||||
file,
|
file,
|
||||||
@ -10531,28 +10530,23 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// Don't throw for image scene daa
|
|
||||||
if (error.name !== "EncodingError") {
|
if (error.name !== "EncodingError") {
|
||||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||||
}
|
}
|
||||||
|
// if EncodingError, fall through to insert as regular image
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no scene is embedded or we fail for whatever reason, fall back
|
const imageFiles = fileItems
|
||||||
// to importing as regular image
|
.map((data) => data.file)
|
||||||
// ---------------------------------------------------------------------
|
.filter((file) => isSupportedImageFile(file));
|
||||||
this.createImageElement({ sceneX, sceneY, imageFile: file });
|
|
||||||
|
|
||||||
return;
|
if (imageFiles.length > 0 && this.isToolSupported("image")) {
|
||||||
}
|
return this.insertImages(imageFiles, sceneX, sceneY);
|
||||||
} catch (error: any) {
|
|
||||||
return this.setState({
|
|
||||||
isLoading: false,
|
|
||||||
errorMessage: error.message,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const libraryJSON = event.dataTransfer.getData(MIME_TYPES.excalidrawlib);
|
const libraryJSON = dataTransferList.getData(MIME_TYPES.excalidrawlib);
|
||||||
if (libraryJSON && typeof libraryJSON === "string") {
|
if (libraryJSON && typeof libraryJSON === "string") {
|
||||||
try {
|
try {
|
||||||
const libraryItems = parseLibraryJSON(libraryJSON);
|
const libraryItems = parseLibraryJSON(libraryJSON);
|
||||||
@ -10567,13 +10561,18 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fileItems.length > 0) {
|
||||||
|
const { file, fileHandle } = fileItems[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
// Attempt to parse an excalidraw/excalidrawlib file
|
// Attempt to parse an excalidraw/excalidrawlib file
|
||||||
await this.loadFileToCanvas(file, fileHandle);
|
await this.loadFileToCanvas(file, fileHandle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (event.dataTransfer?.types?.includes("text/plain")) {
|
const textItem = dataTransferList.findByType(MIME_TYPES.text);
|
||||||
const text = event.dataTransfer?.getData("text");
|
|
||||||
|
if (textItem) {
|
||||||
|
const text = textItem.value;
|
||||||
if (
|
if (
|
||||||
text &&
|
text &&
|
||||||
embeddableURLValidator(text, this.props.validateEmbeddable) &&
|
embeddableURLValidator(text, this.props.validateEmbeddable) &&
|
||||||
|
|||||||
@ -11,7 +11,7 @@ interface ButtonProps
|
|||||||
HTMLButtonElement
|
HTMLButtonElement
|
||||||
> {
|
> {
|
||||||
type?: "button" | "submit" | "reset";
|
type?: "button" | "submit" | "reset";
|
||||||
onSelect: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => any;
|
onSelect: () => any;
|
||||||
/** whether button is in active state */
|
/** whether button is in active state */
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@ -34,7 +34,7 @@ export const Button = ({
|
|||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={composeEventHandlers(rest.onClick, (event) => {
|
onClick={composeEventHandlers(rest.onClick, (event) => {
|
||||||
onSelect(event);
|
onSelect();
|
||||||
})}
|
})}
|
||||||
type={type}
|
type={type}
|
||||||
className={clsx("excalidraw-button", className, { selected })}
|
className={clsx("excalidraw-button", className, { selected })}
|
||||||
|
|||||||
@ -22,6 +22,12 @@
|
|||||||
@include isMobile {
|
@include isMobile {
|
||||||
max-width: 11rem;
|
max-width: 11rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.color-picker-container--no-top-picks {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
grid-template-columns: unset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.color-picker__top-picks {
|
.color-picker__top-picks {
|
||||||
@ -30,18 +36,6 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#canvas-bg-color-picker-container {
|
|
||||||
.color-picker__top-picks {
|
|
||||||
gap: 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-picker-container {
|
|
||||||
@include isMobile {
|
|
||||||
max-width: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-picker__button {
|
.color-picker__button {
|
||||||
--radius: 4px;
|
--radius: 4px;
|
||||||
--size: 1.375rem;
|
--size: 1.375rem;
|
||||||
@ -92,6 +86,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.color-picker__button-background {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
svg {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.active {
|
&.active {
|
||||||
.color-picker__button-outline {
|
.color-picker__button-outline {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import * as Popover from "@radix-ui/react-popover";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { useRef } from "react";
|
import { useRef, useEffect } from "react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
COLOR_OUTLINE_CONTRAST_THRESHOLD,
|
COLOR_OUTLINE_CONTRAST_THRESHOLD,
|
||||||
@ -18,7 +18,12 @@ import { useExcalidrawContainer } from "../App";
|
|||||||
import { ButtonSeparator } from "../ButtonSeparator";
|
import { ButtonSeparator } from "../ButtonSeparator";
|
||||||
import { activeEyeDropperAtom } from "../EyeDropper";
|
import { activeEyeDropperAtom } from "../EyeDropper";
|
||||||
import { PropertiesPopover } from "../PropertiesPopover";
|
import { PropertiesPopover } from "../PropertiesPopover";
|
||||||
import { slashIcon } from "../icons";
|
import { backgroundIcon, slashIcon, strokeIcon } from "../icons";
|
||||||
|
import {
|
||||||
|
saveCaretPosition,
|
||||||
|
restoreCaretPosition,
|
||||||
|
temporarilyDisableTextEditorBlur,
|
||||||
|
} from "../../hooks/useTextEditorFocus";
|
||||||
|
|
||||||
import { ColorInput } from "./ColorInput";
|
import { ColorInput } from "./ColorInput";
|
||||||
import { Picker } from "./Picker";
|
import { Picker } from "./Picker";
|
||||||
@ -67,6 +72,7 @@ interface ColorPickerProps {
|
|||||||
palette?: ColorPaletteCustom | null;
|
palette?: ColorPaletteCustom | null;
|
||||||
topPicks?: ColorTuple;
|
topPicks?: ColorTuple;
|
||||||
updateData: (formData?: any) => void;
|
updateData: (formData?: any) => void;
|
||||||
|
compactMode?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ColorPickerPopupContent = ({
|
const ColorPickerPopupContent = ({
|
||||||
@ -77,6 +83,8 @@ const ColorPickerPopupContent = ({
|
|||||||
elements,
|
elements,
|
||||||
palette = COLOR_PALETTE,
|
palette = COLOR_PALETTE,
|
||||||
updateData,
|
updateData,
|
||||||
|
getOpenPopup,
|
||||||
|
appState,
|
||||||
}: Pick<
|
}: Pick<
|
||||||
ColorPickerProps,
|
ColorPickerProps,
|
||||||
| "type"
|
| "type"
|
||||||
@ -86,7 +94,10 @@ const ColorPickerPopupContent = ({
|
|||||||
| "elements"
|
| "elements"
|
||||||
| "palette"
|
| "palette"
|
||||||
| "updateData"
|
| "updateData"
|
||||||
>) => {
|
| "appState"
|
||||||
|
> & {
|
||||||
|
getOpenPopup: () => AppState["openPopup"];
|
||||||
|
}) => {
|
||||||
const { container } = useExcalidrawContainer();
|
const { container } = useExcalidrawContainer();
|
||||||
const [, setActiveColorPickerSection] = useAtom(activeColorPickerSectionAtom);
|
const [, setActiveColorPickerSection] = useAtom(activeColorPickerSectionAtom);
|
||||||
|
|
||||||
@ -117,6 +128,8 @@ const ColorPickerPopupContent = ({
|
|||||||
<PropertiesPopover
|
<PropertiesPopover
|
||||||
container={container}
|
container={container}
|
||||||
style={{ maxWidth: "13rem" }}
|
style={{ maxWidth: "13rem" }}
|
||||||
|
// Improve focus handling for text editing scenarios
|
||||||
|
preventAutoFocusOnTouch={!!appState.editingTextElement}
|
||||||
onFocusOutside={(event) => {
|
onFocusOutside={(event) => {
|
||||||
// refocus due to eye dropper
|
// refocus due to eye dropper
|
||||||
focusPickerContent();
|
focusPickerContent();
|
||||||
@ -131,8 +144,23 @@ const ColorPickerPopupContent = ({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
|
// only clear if we're still the active popup (avoid racing with switch)
|
||||||
|
if (getOpenPopup() === type) {
|
||||||
updateData({ openPopup: null });
|
updateData({ openPopup: null });
|
||||||
|
}
|
||||||
setActiveColorPickerSection(null);
|
setActiveColorPickerSection(null);
|
||||||
|
|
||||||
|
// Refocus text editor when popover closes if we were editing text
|
||||||
|
if (appState.editingTextElement) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const textEditor = document.querySelector(
|
||||||
|
".excalidraw-wysiwyg",
|
||||||
|
) as HTMLTextAreaElement;
|
||||||
|
if (textEditor) {
|
||||||
|
textEditor.focus();
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{palette ? (
|
{palette ? (
|
||||||
@ -141,7 +169,17 @@ const ColorPickerPopupContent = ({
|
|||||||
palette={palette}
|
palette={palette}
|
||||||
color={color}
|
color={color}
|
||||||
onChange={(changedColor) => {
|
onChange={(changedColor) => {
|
||||||
|
// Save caret position before color change if editing text
|
||||||
|
const savedSelection = appState.editingTextElement
|
||||||
|
? saveCaretPosition()
|
||||||
|
: null;
|
||||||
|
|
||||||
onChange(changedColor);
|
onChange(changedColor);
|
||||||
|
|
||||||
|
// Restore caret position after color change if editing text
|
||||||
|
if (appState.editingTextElement && savedSelection) {
|
||||||
|
restoreCaretPosition(savedSelection);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onEyeDropperToggle={(force) => {
|
onEyeDropperToggle={(force) => {
|
||||||
setEyeDropperState((state) => {
|
setEyeDropperState((state) => {
|
||||||
@ -168,6 +206,7 @@ const ColorPickerPopupContent = ({
|
|||||||
if (eyeDropperState) {
|
if (eyeDropperState) {
|
||||||
setEyeDropperState(null);
|
setEyeDropperState(null);
|
||||||
} else {
|
} else {
|
||||||
|
// close explicitly on Escape
|
||||||
updateData({ openPopup: null });
|
updateData({ openPopup: null });
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -188,11 +227,32 @@ const ColorPickerTrigger = ({
|
|||||||
label,
|
label,
|
||||||
color,
|
color,
|
||||||
type,
|
type,
|
||||||
|
compactMode = false,
|
||||||
|
mode = "background",
|
||||||
|
onToggle,
|
||||||
|
editingTextElement,
|
||||||
}: {
|
}: {
|
||||||
color: string | null;
|
color: string | null;
|
||||||
label: string;
|
label: string;
|
||||||
type: ColorPickerType;
|
type: ColorPickerType;
|
||||||
|
compactMode?: boolean;
|
||||||
|
mode?: "background" | "stroke";
|
||||||
|
onToggle: () => void;
|
||||||
|
editingTextElement?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
|
const handleClick = (e: React.MouseEvent) => {
|
||||||
|
// use pointerdown so we run before outside-close logic
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
// If editing text, temporarily disable the wysiwyg blur event
|
||||||
|
if (editingTextElement) {
|
||||||
|
temporarilyDisableTextEditorBlur();
|
||||||
|
}
|
||||||
|
|
||||||
|
onToggle();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover.Trigger
|
<Popover.Trigger
|
||||||
type="button"
|
type="button"
|
||||||
@ -208,8 +268,37 @@ const ColorPickerTrigger = ({
|
|||||||
? t("labels.showStroke")
|
? t("labels.showStroke")
|
||||||
: t("labels.showBackground")
|
: t("labels.showBackground")
|
||||||
}
|
}
|
||||||
|
data-openpopup={type}
|
||||||
|
onClick={handleClick}
|
||||||
>
|
>
|
||||||
<div className="color-picker__button-outline">{!color && slashIcon}</div>
|
<div className="color-picker__button-outline">{!color && slashIcon}</div>
|
||||||
|
{compactMode && color && (
|
||||||
|
<div className="color-picker__button-background">
|
||||||
|
{mode === "background" ? (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color:
|
||||||
|
color && isColorDark(color, COLOR_OUTLINE_CONTRAST_THRESHOLD)
|
||||||
|
? "#fff"
|
||||||
|
: "#111",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{backgroundIcon}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
color:
|
||||||
|
color && isColorDark(color, COLOR_OUTLINE_CONTRAST_THRESHOLD)
|
||||||
|
? "#fff"
|
||||||
|
: "#111",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{strokeIcon}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Popover.Trigger>
|
</Popover.Trigger>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -224,25 +313,59 @@ export const ColorPicker = ({
|
|||||||
topPicks,
|
topPicks,
|
||||||
updateData,
|
updateData,
|
||||||
appState,
|
appState,
|
||||||
|
compactMode = false,
|
||||||
}: ColorPickerProps) => {
|
}: ColorPickerProps) => {
|
||||||
|
const openRef = useRef(appState.openPopup);
|
||||||
|
useEffect(() => {
|
||||||
|
openRef.current = appState.openPopup;
|
||||||
|
}, [appState.openPopup]);
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div role="dialog" aria-modal="true" className="color-picker-container">
|
<div
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
className={clsx("color-picker-container", {
|
||||||
|
"color-picker-container--no-top-picks": compactMode,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{!compactMode && (
|
||||||
<TopPicks
|
<TopPicks
|
||||||
activeColor={color}
|
activeColor={color}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
type={type}
|
type={type}
|
||||||
topPicks={topPicks}
|
topPicks={topPicks}
|
||||||
/>
|
/>
|
||||||
<ButtonSeparator />
|
)}
|
||||||
|
{!compactMode && <ButtonSeparator />}
|
||||||
<Popover.Root
|
<Popover.Root
|
||||||
open={appState.openPopup === type}
|
open={appState.openPopup === type}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
updateData({ openPopup: open ? type : null });
|
if (open) {
|
||||||
|
updateData({ openPopup: type });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* serves as an active color indicator as well */}
|
{/* serves as an active color indicator as well */}
|
||||||
<ColorPickerTrigger color={color} label={label} type={type} />
|
<ColorPickerTrigger
|
||||||
|
color={color}
|
||||||
|
label={label}
|
||||||
|
type={type}
|
||||||
|
compactMode={compactMode}
|
||||||
|
mode={type === "elementStroke" ? "stroke" : "background"}
|
||||||
|
editingTextElement={!!appState.editingTextElement}
|
||||||
|
onToggle={() => {
|
||||||
|
// atomic switch: if another popup is open, close it first, then open this one next tick
|
||||||
|
if (appState.openPopup === type) {
|
||||||
|
// toggle off on same trigger
|
||||||
|
updateData({ openPopup: null });
|
||||||
|
} else if (appState.openPopup) {
|
||||||
|
updateData({ openPopup: type });
|
||||||
|
} else {
|
||||||
|
// open this one
|
||||||
|
updateData({ openPopup: type });
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
{/* popup content */}
|
{/* popup content */}
|
||||||
{appState.openPopup === type && (
|
{appState.openPopup === type && (
|
||||||
<ColorPickerPopupContent
|
<ColorPickerPopupContent
|
||||||
@ -253,6 +376,8 @@ export const ColorPicker = ({
|
|||||||
elements={elements}
|
elements={elements}
|
||||||
palette={palette}
|
palette={palette}
|
||||||
updateData={updateData}
|
updateData={updateData}
|
||||||
|
getOpenPopup={() => openRef.current}
|
||||||
|
appState={appState}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Popover.Root>
|
</Popover.Root>
|
||||||
|
|||||||
@ -11,5 +11,10 @@
|
|||||||
2rem + 4 * var(--default-button-size)
|
2rem + 4 * var(--default-button-size)
|
||||||
); // 4 gaps + 4 buttons
|
); // 4 gaps + 4 buttons
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--compact {
|
||||||
|
display: block;
|
||||||
|
grid-template-columns: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import * as Popover from "@radix-ui/react-popover";
|
||||||
|
import clsx from "clsx";
|
||||||
import React, { useCallback, useMemo } from "react";
|
import React, { useCallback, useMemo } from "react";
|
||||||
|
|
||||||
import { FONT_FAMILY } from "@excalidraw/common";
|
import { FONT_FAMILY } from "@excalidraw/common";
|
||||||
@ -58,6 +59,7 @@ interface FontPickerProps {
|
|||||||
onHover: (fontFamily: FontFamilyValues) => void;
|
onHover: (fontFamily: FontFamilyValues) => void;
|
||||||
onLeave: () => void;
|
onLeave: () => void;
|
||||||
onPopupChange: (open: boolean) => void;
|
onPopupChange: (open: boolean) => void;
|
||||||
|
compactMode?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FontPicker = React.memo(
|
export const FontPicker = React.memo(
|
||||||
@ -69,6 +71,7 @@ export const FontPicker = React.memo(
|
|||||||
onHover,
|
onHover,
|
||||||
onLeave,
|
onLeave,
|
||||||
onPopupChange,
|
onPopupChange,
|
||||||
|
compactMode = false,
|
||||||
}: FontPickerProps) => {
|
}: FontPickerProps) => {
|
||||||
const defaultFonts = useMemo(() => DEFAULT_FONTS, []);
|
const defaultFonts = useMemo(() => DEFAULT_FONTS, []);
|
||||||
const onSelectCallback = useCallback(
|
const onSelectCallback = useCallback(
|
||||||
@ -81,7 +84,14 @@ export const FontPicker = React.memo(
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div role="dialog" aria-modal="true" className="FontPicker__container">
|
<div
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
className={clsx("FontPicker__container", {
|
||||||
|
"FontPicker__container--compact": compactMode,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{!compactMode && (
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
<RadioSelection<FontFamilyValues | false>
|
<RadioSelection<FontFamilyValues | false>
|
||||||
type="button"
|
type="button"
|
||||||
@ -90,9 +100,13 @@ export const FontPicker = React.memo(
|
|||||||
onClick={onSelectCallback}
|
onClick={onSelectCallback}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<ButtonSeparator />
|
)}
|
||||||
|
{!compactMode && <ButtonSeparator />}
|
||||||
<Popover.Root open={isOpened} onOpenChange={onPopupChange}>
|
<Popover.Root open={isOpened} onOpenChange={onPopupChange}>
|
||||||
<FontPickerTrigger selectedFontFamily={selectedFontFamily} />
|
<FontPickerTrigger
|
||||||
|
selectedFontFamily={selectedFontFamily}
|
||||||
|
isOpened={isOpened}
|
||||||
|
/>
|
||||||
{isOpened && (
|
{isOpened && (
|
||||||
<FontPickerList
|
<FontPickerList
|
||||||
selectedFontFamily={selectedFontFamily}
|
selectedFontFamily={selectedFontFamily}
|
||||||
|
|||||||
@ -25,6 +25,10 @@ import { PropertiesPopover } from "../PropertiesPopover";
|
|||||||
import { QuickSearch } from "../QuickSearch";
|
import { QuickSearch } from "../QuickSearch";
|
||||||
import { ScrollableList } from "../ScrollableList";
|
import { ScrollableList } from "../ScrollableList";
|
||||||
import DropdownMenuGroup from "../dropdownMenu/DropdownMenuGroup";
|
import DropdownMenuGroup from "../dropdownMenu/DropdownMenuGroup";
|
||||||
|
import DropdownMenuItem, {
|
||||||
|
DropDownMenuItemBadgeType,
|
||||||
|
DropDownMenuItemBadge,
|
||||||
|
} from "../dropdownMenu/DropdownMenuItem";
|
||||||
import {
|
import {
|
||||||
FontFamilyCodeIcon,
|
FontFamilyCodeIcon,
|
||||||
FontFamilyHeadingIcon,
|
FontFamilyHeadingIcon,
|
||||||
@ -32,15 +36,8 @@ import {
|
|||||||
FreedrawIcon,
|
FreedrawIcon,
|
||||||
} from "../icons";
|
} from "../icons";
|
||||||
|
|
||||||
import { Ellipsify } from "../Ellipsify";
|
|
||||||
|
|
||||||
import { fontPickerKeyHandler } from "./keyboardNavHandlers";
|
import { fontPickerKeyHandler } from "./keyboardNavHandlers";
|
||||||
|
|
||||||
import {
|
|
||||||
FontPickerListItem,
|
|
||||||
FontPickerListItemBadgeType,
|
|
||||||
} from "./FontPickerListItem";
|
|
||||||
|
|
||||||
import type { JSX } from "react";
|
import type { JSX } from "react";
|
||||||
|
|
||||||
export interface FontDescriptor {
|
export interface FontDescriptor {
|
||||||
@ -49,7 +46,7 @@ export interface FontDescriptor {
|
|||||||
text: string;
|
text: string;
|
||||||
deprecated?: true;
|
deprecated?: true;
|
||||||
badge?: {
|
badge?: {
|
||||||
type: ValueOf<typeof FontPickerListItemBadgeType>;
|
type: ValueOf<typeof DropDownMenuItemBadgeType>;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -93,7 +90,8 @@ export const FontPickerList = React.memo(
|
|||||||
onClose,
|
onClose,
|
||||||
}: FontPickerListProps) => {
|
}: FontPickerListProps) => {
|
||||||
const { container } = useExcalidrawContainer();
|
const { container } = useExcalidrawContainer();
|
||||||
const { fonts } = useApp();
|
const app = useApp();
|
||||||
|
const { fonts } = app;
|
||||||
const { showDeprecatedFonts } = useAppProps();
|
const { showDeprecatedFonts } = useAppProps();
|
||||||
|
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
@ -115,7 +113,7 @@ export const FontPickerList = React.memo(
|
|||||||
Object.assign(fontDescriptor, {
|
Object.assign(fontDescriptor, {
|
||||||
deprecated: metadata.deprecated,
|
deprecated: metadata.deprecated,
|
||||||
badge: {
|
badge: {
|
||||||
type: FontPickerListItemBadgeType.RED,
|
type: DropDownMenuItemBadgeType.RED,
|
||||||
placeholder: t("fontList.badge.old"),
|
placeholder: t("fontList.badge.old"),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -190,6 +188,42 @@ export const FontPickerList = React.memo(
|
|||||||
onLeave,
|
onLeave,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Create a wrapped onSelect function that preserves caret position
|
||||||
|
const wrappedOnSelect = useCallback(
|
||||||
|
(fontFamily: FontFamilyValues) => {
|
||||||
|
// Save caret position before font selection if editing text
|
||||||
|
let savedSelection: { start: number; end: number } | null = null;
|
||||||
|
if (app.state.editingTextElement) {
|
||||||
|
const textEditor = document.querySelector(
|
||||||
|
".excalidraw-wysiwyg",
|
||||||
|
) as HTMLTextAreaElement;
|
||||||
|
if (textEditor) {
|
||||||
|
savedSelection = {
|
||||||
|
start: textEditor.selectionStart,
|
||||||
|
end: textEditor.selectionEnd,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelect(fontFamily);
|
||||||
|
|
||||||
|
// Restore caret position after font selection if editing text
|
||||||
|
if (app.state.editingTextElement && savedSelection) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const textEditor = document.querySelector(
|
||||||
|
".excalidraw-wysiwyg",
|
||||||
|
) as HTMLTextAreaElement;
|
||||||
|
if (textEditor && savedSelection) {
|
||||||
|
textEditor.focus();
|
||||||
|
textEditor.selectionStart = savedSelection.start;
|
||||||
|
textEditor.selectionEnd = savedSelection.end;
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onSelect, app.state.editingTextElement],
|
||||||
|
);
|
||||||
|
|
||||||
const onKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(
|
const onKeyDown = useCallback<KeyboardEventHandler<HTMLDivElement>>(
|
||||||
(event) => {
|
(event) => {
|
||||||
const handled = fontPickerKeyHandler({
|
const handled = fontPickerKeyHandler({
|
||||||
@ -197,7 +231,7 @@ export const FontPickerList = React.memo(
|
|||||||
inputRef,
|
inputRef,
|
||||||
hoveredFont,
|
hoveredFont,
|
||||||
filteredFonts,
|
filteredFonts,
|
||||||
onSelect,
|
onSelect: wrappedOnSelect,
|
||||||
onHover,
|
onHover,
|
||||||
onClose,
|
onClose,
|
||||||
});
|
});
|
||||||
@ -207,7 +241,7 @@ export const FontPickerList = React.memo(
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[hoveredFont, filteredFonts, onSelect, onHover, onClose],
|
[hoveredFont, filteredFonts, wrappedOnSelect, onHover, onClose],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -230,7 +264,7 @@ export const FontPickerList = React.memo(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const renderFont = (font: FontDescriptor, index: number) => (
|
const renderFont = (font: FontDescriptor, index: number) => (
|
||||||
<FontPickerListItem
|
<DropdownMenuItem
|
||||||
key={font.value}
|
key={font.value}
|
||||||
icon={font.icon}
|
icon={font.icon}
|
||||||
value={font.value}
|
value={font.value}
|
||||||
@ -242,8 +276,8 @@ export const FontPickerList = React.memo(
|
|||||||
selected={font.value === selectedFontFamily}
|
selected={font.value === selectedFontFamily}
|
||||||
// allow to tab between search and selected font
|
// allow to tab between search and selected font
|
||||||
tabIndex={font.value === selectedFontFamily ? 0 : -1}
|
tabIndex={font.value === selectedFontFamily ? 0 : -1}
|
||||||
onSelect={() => {
|
onClick={(e) => {
|
||||||
onSelect(font.value);
|
wrappedOnSelect(Number(e.currentTarget.value));
|
||||||
}}
|
}}
|
||||||
onMouseMove={() => {
|
onMouseMove={() => {
|
||||||
if (hoveredFont?.value !== font.value) {
|
if (hoveredFont?.value !== font.value) {
|
||||||
@ -251,13 +285,13 @@ export const FontPickerList = React.memo(
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Ellipsify>{font.text}</Ellipsify>
|
{font.text}
|
||||||
{font.badge && (
|
{font.badge && (
|
||||||
<FontPickerListItem.Badge type={font.badge.type}>
|
<DropDownMenuItemBadge type={font.badge.type}>
|
||||||
{font.badge.placeholder}
|
{font.badge.placeholder}
|
||||||
</FontPickerListItem.Badge>
|
</DropDownMenuItemBadge>
|
||||||
)}
|
)}
|
||||||
</FontPickerListItem>
|
</DropdownMenuItem>
|
||||||
);
|
);
|
||||||
|
|
||||||
const groups = [];
|
const groups = [];
|
||||||
@ -285,9 +319,24 @@ export const FontPickerList = React.memo(
|
|||||||
className="properties-content"
|
className="properties-content"
|
||||||
container={container}
|
container={container}
|
||||||
style={{ width: "15rem" }}
|
style={{ width: "15rem" }}
|
||||||
onClose={onClose}
|
onClose={() => {
|
||||||
|
onClose();
|
||||||
|
|
||||||
|
// Refocus text editor when font picker closes if we were editing text
|
||||||
|
if (app.state.editingTextElement) {
|
||||||
|
setTimeout(() => {
|
||||||
|
const textEditor = document.querySelector(
|
||||||
|
".excalidraw-wysiwyg",
|
||||||
|
) as HTMLTextAreaElement;
|
||||||
|
if (textEditor) {
|
||||||
|
textEditor.focus();
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}}
|
||||||
onPointerLeave={onLeave}
|
onPointerLeave={onLeave}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
|
preventAutoFocusOnTouch={!!app.state.editingTextElement}
|
||||||
>
|
>
|
||||||
<QuickSearch
|
<QuickSearch
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
|
|||||||
@ -1,151 +0,0 @@
|
|||||||
import React, { useEffect, useRef } from "react";
|
|
||||||
|
|
||||||
import { THEME } from "@excalidraw/common";
|
|
||||||
|
|
||||||
import type { ValueOf } from "@excalidraw/common/utility-types";
|
|
||||||
|
|
||||||
import { Button } from "../Button";
|
|
||||||
|
|
||||||
import { useExcalidrawAppState } from "../App";
|
|
||||||
|
|
||||||
import { useDevice } from "../App";
|
|
||||||
|
|
||||||
import { getDropdownMenuItemClassName } from "../dropdownMenu/common";
|
|
||||||
|
|
||||||
import type { JSX } from "react";
|
|
||||||
|
|
||||||
const MenuItemContent = ({
|
|
||||||
textStyle,
|
|
||||||
icon,
|
|
||||||
shortcut,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
icon?: React.ReactNode;
|
|
||||||
shortcut?: string;
|
|
||||||
textStyle?: React.CSSProperties;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) => {
|
|
||||||
const device = useDevice();
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{icon && <div className="dropdown-menu-item__icon">{icon}</div>}
|
|
||||||
<div style={textStyle} className="dropdown-menu-item__text">
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
{shortcut && !device.editor.isMobile && (
|
|
||||||
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const FontPickerListItem = ({
|
|
||||||
icon,
|
|
||||||
value,
|
|
||||||
order,
|
|
||||||
children,
|
|
||||||
shortcut,
|
|
||||||
className,
|
|
||||||
hovered,
|
|
||||||
selected,
|
|
||||||
textStyle,
|
|
||||||
onSelect,
|
|
||||||
onClick,
|
|
||||||
...rest
|
|
||||||
}: {
|
|
||||||
icon?: JSX.Element;
|
|
||||||
value?: string | number | undefined;
|
|
||||||
order?: number;
|
|
||||||
onSelect: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
|
||||||
children: React.ReactNode;
|
|
||||||
shortcut?: string;
|
|
||||||
hovered?: boolean;
|
|
||||||
selected?: boolean;
|
|
||||||
textStyle?: React.CSSProperties;
|
|
||||||
className?: string;
|
|
||||||
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
|
||||||
const ref = useRef<HTMLButtonElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (hovered) {
|
|
||||||
if (order === 0) {
|
|
||||||
// scroll into the first item differently, so it's visible what is above (i.e. group title)
|
|
||||||
ref.current?.scrollIntoView({ block: "end" });
|
|
||||||
} else {
|
|
||||||
ref.current?.scrollIntoView({ block: "nearest" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [hovered, order]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="radix-menu-item">
|
|
||||||
<Button
|
|
||||||
{...rest}
|
|
||||||
ref={ref}
|
|
||||||
onSelect={onSelect}
|
|
||||||
className={getDropdownMenuItemClassName(className, selected, hovered)}
|
|
||||||
title={rest.title ?? rest["aria-label"]}
|
|
||||||
>
|
|
||||||
<MenuItemContent textStyle={textStyle} icon={icon} shortcut={shortcut}>
|
|
||||||
{children}
|
|
||||||
</MenuItemContent>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
FontPickerListItem.displayName = "FontPickerListItem";
|
|
||||||
|
|
||||||
export const FontPickerListItemBadgeType = {
|
|
||||||
GREEN: "green",
|
|
||||||
RED: "red",
|
|
||||||
BLUE: "blue",
|
|
||||||
} as const;
|
|
||||||
|
|
||||||
export const FontPickerListItemBadge = ({
|
|
||||||
type = FontPickerListItemBadgeType.BLUE,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
type?: ValueOf<typeof FontPickerListItemBadgeType>;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) => {
|
|
||||||
const { theme } = useExcalidrawAppState();
|
|
||||||
const style = {
|
|
||||||
display: "inline-flex",
|
|
||||||
marginLeft: "auto",
|
|
||||||
padding: "2px 4px",
|
|
||||||
borderRadius: 6,
|
|
||||||
fontSize: 9,
|
|
||||||
fontFamily: "Cascadia, monospace",
|
|
||||||
border: theme === THEME.LIGHT ? "1.5px solid white" : "none",
|
|
||||||
};
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case FontPickerListItemBadgeType.GREEN:
|
|
||||||
Object.assign(style, {
|
|
||||||
backgroundColor: "var(--background-color-badge)",
|
|
||||||
color: "var(--color-badge)",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case FontPickerListItemBadgeType.RED:
|
|
||||||
Object.assign(style, {
|
|
||||||
backgroundColor: "pink",
|
|
||||||
color: "darkred",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case FontPickerListItemBadgeType.BLUE:
|
|
||||||
default:
|
|
||||||
Object.assign(style, {
|
|
||||||
background: "var(--color-promo)",
|
|
||||||
color: "var(--color-surface-lowest)",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="DropDownMenuItemBadge" style={style}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
FontPickerListItemBadge.displayName = "DropdownMenuItemBadge";
|
|
||||||
|
|
||||||
FontPickerListItem.Badge = FontPickerListItemBadge;
|
|
||||||
@ -1,5 +1,4 @@
|
|||||||
import * as Popover from "@radix-ui/react-popover";
|
import * as Popover from "@radix-ui/react-popover";
|
||||||
import { useMemo } from "react";
|
|
||||||
|
|
||||||
import type { FontFamilyValues } from "@excalidraw/element/types";
|
import type { FontFamilyValues } from "@excalidraw/element/types";
|
||||||
|
|
||||||
@ -7,33 +6,38 @@ import { t } from "../../i18n";
|
|||||||
import { ButtonIcon } from "../ButtonIcon";
|
import { ButtonIcon } from "../ButtonIcon";
|
||||||
import { TextIcon } from "../icons";
|
import { TextIcon } from "../icons";
|
||||||
|
|
||||||
import { isDefaultFont } from "./FontPicker";
|
import { useExcalidrawSetAppState } from "../App";
|
||||||
|
|
||||||
interface FontPickerTriggerProps {
|
interface FontPickerTriggerProps {
|
||||||
selectedFontFamily: FontFamilyValues | null;
|
selectedFontFamily: FontFamilyValues | null;
|
||||||
|
isOpened?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FontPickerTrigger = ({
|
export const FontPickerTrigger = ({
|
||||||
selectedFontFamily,
|
selectedFontFamily,
|
||||||
|
isOpened = false,
|
||||||
}: FontPickerTriggerProps) => {
|
}: FontPickerTriggerProps) => {
|
||||||
const isTriggerActive = useMemo(
|
const setAppState = useExcalidrawSetAppState();
|
||||||
() => Boolean(selectedFontFamily && !isDefaultFont(selectedFontFamily)),
|
|
||||||
[selectedFontFamily],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Popover.Trigger asChild>
|
<Popover.Trigger asChild>
|
||||||
{/* Empty div as trigger so it's stretched 100% due to different button sizes */}
|
<div data-openpopup="fontFamily" className="properties-trigger">
|
||||||
<div>
|
|
||||||
<ButtonIcon
|
<ButtonIcon
|
||||||
standalone
|
standalone
|
||||||
icon={TextIcon}
|
icon={TextIcon}
|
||||||
title={t("labels.showFonts")}
|
title={t("labels.showFonts")}
|
||||||
className="properties-trigger"
|
className="properties-trigger"
|
||||||
testId={"font-family-show-fonts"}
|
testId={"font-family-show-fonts"}
|
||||||
active={isTriggerActive}
|
active={isOpened}
|
||||||
// no-op
|
onClick={() => {
|
||||||
onClick={() => {}}
|
setAppState((appState) => ({
|
||||||
|
openPopup:
|
||||||
|
appState.openPopup === "fontFamily" ? null : appState.openPopup,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
border: "none",
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Popover.Trigger>
|
</Popover.Trigger>
|
||||||
|
|||||||
@ -238,10 +238,7 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
|
|||||||
shortcuts={[getShortcutKey("Enter"), getShortcutKey("Escape")]}
|
shortcuts={[getShortcutKey("Enter"), getShortcutKey("Escape")]}
|
||||||
isOr={true}
|
isOr={true}
|
||||||
/>
|
/>
|
||||||
<Shortcut
|
<Shortcut label={t("toolBar.lock")} shortcuts={[KEYS.Q]} />
|
||||||
label={t("toolBar.lock")}
|
|
||||||
shortcuts={[getShortcutFromShortcutName("toolLock")]}
|
|
||||||
/>
|
|
||||||
<Shortcut
|
<Shortcut
|
||||||
label={t("helpDialog.preventBinding")}
|
label={t("helpDialog.preventBinding")}
|
||||||
shortcuts={[getShortcutKey("CtrlOrCmd")]}
|
shortcuts={[getShortcutKey("CtrlOrCmd")]}
|
||||||
|
|||||||
@ -24,6 +24,10 @@
|
|||||||
gap: 0.75rem;
|
gap: 0.75rem;
|
||||||
pointer-events: none !important;
|
pointer-events: none !important;
|
||||||
|
|
||||||
|
&--compact {
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
& > * {
|
& > * {
|
||||||
pointer-events: var(--ui-pointerEvents);
|
pointer-events: var(--ui-pointerEvents);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import React from "react";
|
|||||||
import {
|
import {
|
||||||
CLASSES,
|
CLASSES,
|
||||||
DEFAULT_SIDEBAR,
|
DEFAULT_SIDEBAR,
|
||||||
|
MQ_MIN_WIDTH_DESKTOP,
|
||||||
TOOL_TYPE,
|
TOOL_TYPE,
|
||||||
arrayToMap,
|
arrayToMap,
|
||||||
capitalizeString,
|
capitalizeString,
|
||||||
@ -28,7 +29,11 @@ import { useAtom, useAtomValue } from "../editor-jotai";
|
|||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { calculateScrollCenter } from "../scene";
|
import { calculateScrollCenter } from "../scene";
|
||||||
|
|
||||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
import {
|
||||||
|
SelectedShapeActions,
|
||||||
|
ShapesSwitcher,
|
||||||
|
CompactShapeActions,
|
||||||
|
} from "./Actions";
|
||||||
import { LoadingMessage } from "./LoadingMessage";
|
import { LoadingMessage } from "./LoadingMessage";
|
||||||
import { LockButton } from "./LockButton";
|
import { LockButton } from "./LockButton";
|
||||||
import { MobileMenu } from "./MobileMenu";
|
import { MobileMenu } from "./MobileMenu";
|
||||||
@ -157,6 +162,25 @@ const LayerUI = ({
|
|||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
const tunnels = useInitializeTunnels();
|
const tunnels = useInitializeTunnels();
|
||||||
|
|
||||||
|
const spacing =
|
||||||
|
appState.stylesPanelMode === "compact"
|
||||||
|
? {
|
||||||
|
menuTopGap: 4,
|
||||||
|
toolbarColGap: 4,
|
||||||
|
toolbarRowGap: 1,
|
||||||
|
toolbarInnerRowGap: 0.5,
|
||||||
|
islandPadding: 1,
|
||||||
|
collabMarginLeft: 8,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
menuTopGap: 6,
|
||||||
|
toolbarColGap: 4,
|
||||||
|
toolbarRowGap: 1,
|
||||||
|
toolbarInnerRowGap: 1,
|
||||||
|
islandPadding: 1,
|
||||||
|
collabMarginLeft: 8,
|
||||||
|
};
|
||||||
|
|
||||||
const TunnelsJotaiProvider = tunnels.tunnelsJotai.Provider;
|
const TunnelsJotaiProvider = tunnels.tunnelsJotai.Provider;
|
||||||
|
|
||||||
const [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom);
|
const [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom);
|
||||||
@ -209,13 +233,35 @@ const LayerUI = ({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderSelectedShapeActions = () => (
|
const renderSelectedShapeActions = () => {
|
||||||
|
const isCompactMode = appState.stylesPanelMode === "compact";
|
||||||
|
|
||||||
|
return (
|
||||||
<Section
|
<Section
|
||||||
heading="selectedShapeActions"
|
heading="selectedShapeActions"
|
||||||
className={clsx("selected-shape-actions zen-mode-transition", {
|
className={clsx("selected-shape-actions zen-mode-transition", {
|
||||||
"transition-left": appState.zenModeEnabled,
|
"transition-left": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
|
{isCompactMode ? (
|
||||||
|
<Island
|
||||||
|
className={clsx("compact-shape-actions-island")}
|
||||||
|
padding={0}
|
||||||
|
style={{
|
||||||
|
// we want to make sure this doesn't overflow so subtracting the
|
||||||
|
// approximate height of hamburgerMenu + footer
|
||||||
|
maxHeight: `${appState.height - 166}px`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CompactShapeActions
|
||||||
|
appState={appState}
|
||||||
|
elementsMap={app.scene.getNonDeletedElementsMap()}
|
||||||
|
renderAction={actionManager.renderAction}
|
||||||
|
app={app}
|
||||||
|
setAppState={setAppState}
|
||||||
|
/>
|
||||||
|
</Island>
|
||||||
|
) : (
|
||||||
<Island
|
<Island
|
||||||
className={CLASSES.SHAPE_ACTIONS_MENU}
|
className={CLASSES.SHAPE_ACTIONS_MENU}
|
||||||
padding={2}
|
padding={2}
|
||||||
@ -232,8 +278,10 @@ const LayerUI = ({
|
|||||||
app={app}
|
app={app}
|
||||||
/>
|
/>
|
||||||
</Island>
|
</Island>
|
||||||
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const renderFixedSideContainer = () => {
|
const renderFixedSideContainer = () => {
|
||||||
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
||||||
@ -250,9 +298,19 @@ const LayerUI = ({
|
|||||||
return (
|
return (
|
||||||
<FixedSideContainer side="top">
|
<FixedSideContainer side="top">
|
||||||
<div className="App-menu App-menu_top">
|
<div className="App-menu App-menu_top">
|
||||||
<Stack.Col gap={6} className={clsx("App-menu_top__left")}>
|
<Stack.Col
|
||||||
|
gap={spacing.menuTopGap}
|
||||||
|
className={clsx("App-menu_top__left")}
|
||||||
|
>
|
||||||
{renderCanvasActions()}
|
{renderCanvasActions()}
|
||||||
|
<div
|
||||||
|
className={clsx("selected-shape-actions-container", {
|
||||||
|
"selected-shape-actions-container--compact":
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
|
})}
|
||||||
|
>
|
||||||
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
||||||
|
</div>
|
||||||
</Stack.Col>
|
</Stack.Col>
|
||||||
{!appState.viewModeEnabled &&
|
{!appState.viewModeEnabled &&
|
||||||
appState.openDialog?.name !== "elementLinkSelector" && (
|
appState.openDialog?.name !== "elementLinkSelector" && (
|
||||||
@ -262,17 +320,19 @@ const LayerUI = ({
|
|||||||
{renderWelcomeScreen && (
|
{renderWelcomeScreen && (
|
||||||
<tunnels.WelcomeScreenToolbarHintTunnel.Out />
|
<tunnels.WelcomeScreenToolbarHintTunnel.Out />
|
||||||
)}
|
)}
|
||||||
<Stack.Col gap={4} align="start">
|
<Stack.Col gap={spacing.toolbarColGap} align="start">
|
||||||
<Stack.Row
|
<Stack.Row
|
||||||
gap={1}
|
gap={spacing.toolbarRowGap}
|
||||||
className={clsx("App-toolbar-container", {
|
className={clsx("App-toolbar-container", {
|
||||||
"zen-mode": appState.zenModeEnabled,
|
"zen-mode": appState.zenModeEnabled,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Island
|
<Island
|
||||||
padding={1}
|
padding={spacing.islandPadding}
|
||||||
className={clsx("App-toolbar", {
|
className={clsx("App-toolbar", {
|
||||||
"zen-mode": appState.zenModeEnabled,
|
"zen-mode": appState.zenModeEnabled,
|
||||||
|
"App-toolbar--compact":
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<HintViewer
|
<HintViewer
|
||||||
@ -282,7 +342,7 @@ const LayerUI = ({
|
|||||||
app={app}
|
app={app}
|
||||||
/>
|
/>
|
||||||
{heading}
|
{heading}
|
||||||
<Stack.Row gap={1}>
|
<Stack.Row gap={spacing.toolbarInnerRowGap}>
|
||||||
<PenModeButton
|
<PenModeButton
|
||||||
zenModeEnabled={appState.zenModeEnabled}
|
zenModeEnabled={appState.zenModeEnabled}
|
||||||
checked={appState.penMode}
|
checked={appState.penMode}
|
||||||
@ -316,7 +376,7 @@ const LayerUI = ({
|
|||||||
{isCollaborating && (
|
{isCollaborating && (
|
||||||
<Island
|
<Island
|
||||||
style={{
|
style={{
|
||||||
marginLeft: 8,
|
marginLeft: spacing.collabMarginLeft,
|
||||||
alignSelf: "center",
|
alignSelf: "center",
|
||||||
height: "fit-content",
|
height: "fit-content",
|
||||||
}}
|
}}
|
||||||
@ -344,6 +404,8 @@ const LayerUI = ({
|
|||||||
"layer-ui__wrapper__top-right zen-mode-transition",
|
"layer-ui__wrapper__top-right zen-mode-transition",
|
||||||
{
|
{
|
||||||
"transition-right": appState.zenModeEnabled,
|
"transition-right": appState.zenModeEnabled,
|
||||||
|
"layer-ui__wrapper__top-right--compact":
|
||||||
|
appState.stylesPanelMode === "compact",
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@ -418,7 +480,9 @@ const LayerUI = ({
|
|||||||
}}
|
}}
|
||||||
tab={DEFAULT_SIDEBAR.defaultTab}
|
tab={DEFAULT_SIDEBAR.defaultTab}
|
||||||
>
|
>
|
||||||
{t("toolBar.library")}
|
{appState.stylesPanelMode === "full" &&
|
||||||
|
appState.width >= MQ_MIN_WIDTH_DESKTOP &&
|
||||||
|
t("toolBar.library")}
|
||||||
</DefaultSidebar.Trigger>
|
</DefaultSidebar.Trigger>
|
||||||
<DefaultOverwriteConfirmDialog />
|
<DefaultOverwriteConfirmDialog />
|
||||||
{appState.openDialog?.name === "ttd" && <TTDDialog __fallback />}
|
{appState.openDialog?.name === "ttd" && <TTDDialog __fallback />}
|
||||||
|
|||||||
@ -194,7 +194,6 @@ export const LibraryDropdownMenuButton: React.FC<{
|
|||||||
<DropdownMenu open={isLibraryMenuOpen}>
|
<DropdownMenu open={isLibraryMenuOpen}>
|
||||||
<DropdownMenu.Trigger
|
<DropdownMenu.Trigger
|
||||||
onToggle={() => setIsLibraryMenuOpen(!isLibraryMenuOpen)}
|
onToggle={() => setIsLibraryMenuOpen(!isLibraryMenuOpen)}
|
||||||
aria-label="Library menu"
|
|
||||||
>
|
>
|
||||||
{DotsIcon}
|
{DotsIcon}
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
@ -202,7 +201,6 @@ export const LibraryDropdownMenuButton: React.FC<{
|
|||||||
onClickOutside={() => setIsLibraryMenuOpen(false)}
|
onClickOutside={() => setIsLibraryMenuOpen(false)}
|
||||||
onSelect={() => setIsLibraryMenuOpen(false)}
|
onSelect={() => setIsLibraryMenuOpen(false)}
|
||||||
className="library-menu"
|
className="library-menu"
|
||||||
align="end"
|
|
||||||
>
|
>
|
||||||
{!itemsSelected && (
|
{!itemsSelected && (
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
|
|||||||
@ -17,6 +17,7 @@ interface PropertiesPopoverProps {
|
|||||||
onPointerLeave?: React.PointerEventHandler<HTMLDivElement>;
|
onPointerLeave?: React.PointerEventHandler<HTMLDivElement>;
|
||||||
onFocusOutside?: Popover.PopoverContentProps["onFocusOutside"];
|
onFocusOutside?: Popover.PopoverContentProps["onFocusOutside"];
|
||||||
onPointerDownOutside?: Popover.PopoverContentProps["onPointerDownOutside"];
|
onPointerDownOutside?: Popover.PopoverContentProps["onPointerDownOutside"];
|
||||||
|
preventAutoFocusOnTouch?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PropertiesPopover = React.forwardRef<
|
export const PropertiesPopover = React.forwardRef<
|
||||||
@ -34,6 +35,7 @@ export const PropertiesPopover = React.forwardRef<
|
|||||||
onFocusOutside,
|
onFocusOutside,
|
||||||
onPointerLeave,
|
onPointerLeave,
|
||||||
onPointerDownOutside,
|
onPointerDownOutside,
|
||||||
|
preventAutoFocusOnTouch = false,
|
||||||
},
|
},
|
||||||
ref,
|
ref,
|
||||||
) => {
|
) => {
|
||||||
@ -64,6 +66,12 @@ export const PropertiesPopover = React.forwardRef<
|
|||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onFocusOutside={onFocusOutside}
|
onFocusOutside={onFocusOutside}
|
||||||
onPointerDownOutside={onPointerDownOutside}
|
onPointerDownOutside={onPointerDownOutside}
|
||||||
|
onOpenAutoFocus={(e) => {
|
||||||
|
// prevent auto-focus on touch devices to avoid keyboard popup
|
||||||
|
if (preventAutoFocusOnTouch && device.isTouchScreen) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}}
|
||||||
onCloseAutoFocus={(e) => {
|
onCloseAutoFocus={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
// prevents focusing the trigger
|
// prevents focusing the trigger
|
||||||
|
|||||||
@ -26,9 +26,9 @@ export const TTDDialogTrigger = ({
|
|||||||
setAppState({ openDialog: { name: "ttd", tab: "text-to-diagram" } });
|
setAppState({ openDialog: { name: "ttd", tab: "text-to-diagram" } });
|
||||||
}}
|
}}
|
||||||
icon={icon ?? brainIcon}
|
icon={icon ?? brainIcon}
|
||||||
badge={<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>}
|
|
||||||
>
|
>
|
||||||
{children ?? t("labels.textToDiagram")}
|
{children ?? t("labels.textToDiagram")}
|
||||||
|
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
</TTDDialogTriggerTunnel.In>
|
</TTDDialogTriggerTunnel.In>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -10,6 +10,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--compact {
|
||||||
|
.ToolIcon__keybinding {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.App-toolbar__divider {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&__divider {
|
&__divider {
|
||||||
width: 1px;
|
width: 1px;
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
|
|||||||
@ -1,45 +1,20 @@
|
|||||||
@import "../../css/variables.module";
|
@import "../../css/variables.module.scss";
|
||||||
|
|
||||||
.excalidraw {
|
.excalidraw {
|
||||||
[data-dropdown-menu-trigger] + [data-radix-popper-content-wrapper] {
|
|
||||||
z-index: 2 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-menu {
|
.dropdown-menu {
|
||||||
max-width: 16rem;
|
position: absolute;
|
||||||
margin-top: 0.25rem;
|
top: 100%;
|
||||||
|
margin-top: 0.5rem;
|
||||||
&__submenu-trigger {
|
|
||||||
&[aria-expanded="true"] {
|
|
||||||
.dropdown-menu-item {
|
|
||||||
background-color: var(--button-hover-bg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__submenu-trigger-icon {
|
|
||||||
margin-left: auto;
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
.radix-menu-item {
|
|
||||||
&:focus-visible {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.dropdown-submenu {
|
|
||||||
margin-left: -0.75rem;
|
|
||||||
min-width: 16rem;
|
|
||||||
max-width: 20rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--mobile {
|
&--mobile {
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
row-gap: 0.75rem;
|
||||||
|
|
||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
grid-template-columns: minmax(0, 1fr);
|
|
||||||
padding: 8px 8px;
|
padding: 8px 8px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
background-color: var(--island-bg-color);
|
// background-color: var(--island-bg-color);
|
||||||
box-shadow: var(--shadow-island);
|
box-shadow: var(--shadow-island);
|
||||||
border-radius: var(--border-radius-lg);
|
border-radius: var(--border-radius-lg);
|
||||||
position: relative;
|
position: relative;
|
||||||
@ -55,14 +30,13 @@
|
|||||||
|
|
||||||
.dropdown-menu-container {
|
.dropdown-menu-container {
|
||||||
background-color: var(--island-bg-color);
|
background-color: var(--island-bg-color);
|
||||||
max-height: var(--radix-popper-available-height);
|
max-height: calc(100vh - 150px);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
--gap: 2;
|
--gap: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown-menu-item-base {
|
.dropdown-menu-item-base {
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0 0.625rem;
|
|
||||||
column-gap: 0.625rem;
|
column-gap: 0.625rem;
|
||||||
font-size: 0.875rem;
|
font-size: 0.875rem;
|
||||||
color: var(--color-on-surface);
|
color: var(--color-on-surface);
|
||||||
@ -70,7 +44,6 @@
|
|||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
justify-content: flex-start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.manual-hover {
|
&.manual-hover {
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import DropdownMenuContent from "./DropdownMenuContent";
|
import DropdownMenuContent from "./DropdownMenuContent";
|
||||||
import DropdownMenuGroup from "./DropdownMenuGroup";
|
import DropdownMenuGroup from "./DropdownMenuGroup";
|
||||||
import DropdownMenuItem from "./DropdownMenuItem";
|
import DropdownMenuItem from "./DropdownMenuItem";
|
||||||
@ -25,12 +23,11 @@ const DropdownMenu = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const MenuTriggerComp = getMenuTriggerComponent(children);
|
const MenuTriggerComp = getMenuTriggerComponent(children);
|
||||||
const MenuContentComp = getMenuContentComponent(children);
|
const MenuContentComp = getMenuContentComponent(children);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.Root open={open} modal={false}>
|
<>
|
||||||
{MenuTriggerComp}
|
{MenuTriggerComp}
|
||||||
{MenuContentComp}
|
{open && MenuContentComp}
|
||||||
</DropdownMenuPrimitive.Root>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,6 @@ import React, { useEffect, useRef } from "react";
|
|||||||
|
|
||||||
import { EVENT, KEYS } from "@excalidraw/common";
|
import { EVENT, KEYS } from "@excalidraw/common";
|
||||||
|
|
||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import { useOutsideClick } from "../../hooks/useOutsideClick";
|
import { useOutsideClick } from "../../hooks/useOutsideClick";
|
||||||
import { useStable } from "../../hooks/useStable";
|
import { useStable } from "../../hooks/useStable";
|
||||||
import { useDevice } from "../App";
|
import { useDevice } from "../App";
|
||||||
@ -19,9 +17,6 @@ const MenuContent = ({
|
|||||||
className = "",
|
className = "",
|
||||||
onSelect,
|
onSelect,
|
||||||
style,
|
style,
|
||||||
sideOffset = 4,
|
|
||||||
align = "start",
|
|
||||||
collisionPadding,
|
|
||||||
}: {
|
}: {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
onClickOutside?: () => void;
|
onClickOutside?: () => void;
|
||||||
@ -31,11 +26,6 @@ const MenuContent = ({
|
|||||||
*/
|
*/
|
||||||
onSelect?: (event: Event) => void;
|
onSelect?: (event: Event) => void;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
sideOffset?: number;
|
|
||||||
align?: "start" | "center" | "end";
|
|
||||||
collisionPadding?:
|
|
||||||
| number
|
|
||||||
| Partial<Record<"top" | "right" | "bottom" | "left", number>>;
|
|
||||||
}) => {
|
}) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
const menuRef = useRef<HTMLDivElement>(null);
|
const menuRef = useRef<HTMLDivElement>(null);
|
||||||
@ -72,15 +62,11 @@ const MenuContent = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenuContentPropsContext.Provider value={{ onSelect }}>
|
<DropdownMenuContentPropsContext.Provider value={{ onSelect }}>
|
||||||
<DropdownMenuPrimitive.Content
|
<div
|
||||||
ref={menuRef}
|
ref={menuRef}
|
||||||
className={classNames}
|
className={classNames}
|
||||||
style={style}
|
style={style}
|
||||||
data-testid="dropdown-menu"
|
data-testid="dropdown-menu"
|
||||||
side="bottom"
|
|
||||||
sideOffset={sideOffset}
|
|
||||||
align={align}
|
|
||||||
collisionPadding={collisionPadding}
|
|
||||||
>
|
>
|
||||||
{/* the zIndex ensures this menu has higher stacking order,
|
{/* the zIndex ensures this menu has higher stacking order,
|
||||||
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
see https://github.com/excalidraw/excalidraw/pull/1445 */}
|
||||||
@ -95,7 +81,7 @@ const MenuContent = ({
|
|||||||
{children}
|
{children}
|
||||||
</Island>
|
</Island>
|
||||||
)}
|
)}
|
||||||
</DropdownMenuPrimitive.Content>
|
</div>
|
||||||
</DropdownMenuContentPropsContext.Provider>
|
</DropdownMenuContentPropsContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
import React, { useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
|
|
||||||
import { THEME } from "@excalidraw/common";
|
import { THEME } from "@excalidraw/common";
|
||||||
|
|
||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import type { ValueOf } from "@excalidraw/common/utility-types";
|
import type { ValueOf } from "@excalidraw/common/utility-types";
|
||||||
|
|
||||||
import { Button } from "../Button";
|
|
||||||
|
|
||||||
import { useExcalidrawAppState } from "../App";
|
import { useExcalidrawAppState } from "../App";
|
||||||
|
|
||||||
import MenuItemContent from "./DropdownMenuItemContent";
|
import MenuItemContent from "./DropdownMenuItemContent";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getDropdownMenuItemClassName,
|
getDropdownMenuItemClassName,
|
||||||
useHandleDropdownMenuItemClick,
|
useHandleDropdownMenuItemClick,
|
||||||
@ -22,45 +17,55 @@ import type { JSX } from "react";
|
|||||||
const DropdownMenuItem = ({
|
const DropdownMenuItem = ({
|
||||||
icon,
|
icon,
|
||||||
value,
|
value,
|
||||||
badge,
|
|
||||||
order,
|
order,
|
||||||
children,
|
children,
|
||||||
shortcut,
|
shortcut,
|
||||||
className,
|
className,
|
||||||
|
hovered,
|
||||||
selected,
|
selected,
|
||||||
|
textStyle,
|
||||||
onSelect,
|
onSelect,
|
||||||
onClick,
|
onClick,
|
||||||
...rest
|
...rest
|
||||||
}: {
|
}: {
|
||||||
icon?: JSX.Element;
|
icon?: JSX.Element;
|
||||||
badge?: React.ReactNode;
|
|
||||||
value?: string | number | undefined;
|
value?: string | number | undefined;
|
||||||
order?: number;
|
order?: number;
|
||||||
onSelect?: (event: Event) => void;
|
onSelect?: (event: Event) => void;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
|
hovered?: boolean;
|
||||||
selected?: boolean;
|
selected?: boolean;
|
||||||
|
textStyle?: React.CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
||||||
const handleClick = useHandleDropdownMenuItemClick(onClick, onSelect);
|
const handleClick = useHandleDropdownMenuItemClick(onClick, onSelect);
|
||||||
const ref = useRef<HTMLButtonElement>(null);
|
const ref = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hovered) {
|
||||||
|
if (order === 0) {
|
||||||
|
// scroll into the first item differently, so it's visible what is above (i.e. group title)
|
||||||
|
ref.current?.scrollIntoView({ block: "end" });
|
||||||
|
} else {
|
||||||
|
ref.current?.scrollIntoView({ block: "nearest" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [hovered, order]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.Item className="radix-menu-item">
|
<button
|
||||||
<Button
|
|
||||||
{...rest}
|
{...rest}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
onSelect={handleClick}
|
value={value}
|
||||||
className={getDropdownMenuItemClassName(className)}
|
onClick={handleClick}
|
||||||
|
className={getDropdownMenuItemClassName(className, selected, hovered)}
|
||||||
title={rest.title ?? rest["aria-label"]}
|
title={rest.title ?? rest["aria-label"]}
|
||||||
>
|
>
|
||||||
<MenuItemContent icon={icon} shortcut={shortcut} badge={badge}>
|
<MenuItemContent textStyle={textStyle} icon={icon} shortcut={shortcut}>
|
||||||
{children}
|
{children}
|
||||||
</MenuItemContent>
|
</MenuItemContent>
|
||||||
</Button>
|
</button>
|
||||||
</DropdownMenuPrimitive.Item>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
DropdownMenuItem.displayName = "DropdownMenuItem";
|
DropdownMenuItem.displayName = "DropdownMenuItem";
|
||||||
|
|||||||
@ -2,24 +2,25 @@ import { useDevice } from "../App";
|
|||||||
|
|
||||||
import { Ellipsify } from "../Ellipsify";
|
import { Ellipsify } from "../Ellipsify";
|
||||||
|
|
||||||
|
import type { JSX } from "react";
|
||||||
|
|
||||||
const MenuItemContent = ({
|
const MenuItemContent = ({
|
||||||
|
textStyle,
|
||||||
icon,
|
icon,
|
||||||
badge,
|
|
||||||
shortcut,
|
shortcut,
|
||||||
children,
|
children,
|
||||||
}: {
|
}: {
|
||||||
icon?: React.ReactNode;
|
icon?: JSX.Element;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
|
textStyle?: React.CSSProperties;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
badge?: React.ReactNode;
|
|
||||||
}) => {
|
}) => {
|
||||||
const device = useDevice();
|
const device = useDevice();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{icon && <div className="dropdown-menu-item__icon">{icon}</div>}
|
{icon && <div className="dropdown-menu-item__icon">{icon}</div>}
|
||||||
<div className="dropdown-menu-item__text">
|
<div style={textStyle} className="dropdown-menu-item__text">
|
||||||
<Ellipsify>{children}</Ellipsify>
|
<Ellipsify>{children}</Ellipsify>
|
||||||
{badge}
|
|
||||||
</div>
|
</div>
|
||||||
{shortcut && !device.editor.isMobile && (
|
{shortcut && !device.editor.isMobile && (
|
||||||
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
<div className="dropdown-menu-item__shortcut">{shortcut}</div>
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import {
|
|
||||||
getSubMenuContentComponent,
|
|
||||||
getSubMenuTriggerComponent,
|
|
||||||
} from "./dropdownMenuUtils";
|
|
||||||
import DropdownMenuSubTrigger from "./DropdownMenuSubTrigger";
|
|
||||||
import DropdownMenuSubContent from "./DropdownMenuSubContent";
|
|
||||||
import DropdownMenuSubItem from "./DropdownMenuSubItem";
|
|
||||||
|
|
||||||
const DropdownMenuSub = ({ children }: { children?: React.ReactNode }) => {
|
|
||||||
const MenuTriggerComp = getSubMenuTriggerComponent(children);
|
|
||||||
const MenuContentComp = getSubMenuContentComponent(children);
|
|
||||||
return (
|
|
||||||
<DropdownMenuPrimitive.Sub>
|
|
||||||
{MenuTriggerComp}
|
|
||||||
{MenuContentComp}
|
|
||||||
</DropdownMenuPrimitive.Sub>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
DropdownMenuSub.Trigger = DropdownMenuSubTrigger;
|
|
||||||
DropdownMenuSub.Content = DropdownMenuSubContent;
|
|
||||||
DropdownMenuSub.Item = DropdownMenuSubItem;
|
|
||||||
|
|
||||||
export default DropdownMenuSub;
|
|
||||||
DropdownMenuSub.displayName = "DropdownMenuSub";
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import clsx from "clsx";
|
|
||||||
|
|
||||||
import { useDevice } from "../App";
|
|
||||||
import Stack from "../Stack";
|
|
||||||
import { Island } from "../Island";
|
|
||||||
|
|
||||||
const DropdownMenuSubContent = ({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
children?: React.ReactNode;
|
|
||||||
className?: string;
|
|
||||||
}) => {
|
|
||||||
const device = useDevice();
|
|
||||||
|
|
||||||
const classNames = clsx(`dropdown-menu dropdown-submenu ${className}`, {
|
|
||||||
"dropdown-menu--mobile": device.editor.isMobile,
|
|
||||||
}).trim();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DropdownMenuPrimitive.SubContent
|
|
||||||
className={classNames}
|
|
||||||
sideOffset={8}
|
|
||||||
alignOffset={-4}
|
|
||||||
>
|
|
||||||
{device.editor.isMobile ? (
|
|
||||||
<Stack.Col className="dropdown-menu-container">{children}</Stack.Col>
|
|
||||||
) : (
|
|
||||||
<Island
|
|
||||||
className="dropdown-menu-container"
|
|
||||||
padding={1}
|
|
||||||
style={{ zIndex: 1 }}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Island>
|
|
||||||
)}
|
|
||||||
</DropdownMenuPrimitive.SubContent>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DropdownMenuSubContent;
|
|
||||||
DropdownMenuSubContent.displayName = "DropdownMenuSubContent";
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import { Button } from "../Button";
|
|
||||||
|
|
||||||
import MenuItemContent from "./DropdownMenuItemContent";
|
|
||||||
import {
|
|
||||||
getDropdownMenuItemClassName,
|
|
||||||
useHandleDropdownMenuItemClick,
|
|
||||||
} from "./common";
|
|
||||||
|
|
||||||
const DropdownMenuSubItem = ({
|
|
||||||
icon,
|
|
||||||
onSelect,
|
|
||||||
children,
|
|
||||||
shortcut,
|
|
||||||
className,
|
|
||||||
...rest
|
|
||||||
}: {
|
|
||||||
icon?: React.ReactNode;
|
|
||||||
onSelect: (event: Event) => void;
|
|
||||||
children: React.ReactNode;
|
|
||||||
shortcut?: string;
|
|
||||||
className?: string;
|
|
||||||
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onSelect">) => {
|
|
||||||
const handleClick = useHandleDropdownMenuItemClick(rest.onClick, onSelect);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DropdownMenuPrimitive.Item className="radix-menu-item">
|
|
||||||
<Button
|
|
||||||
{...rest}
|
|
||||||
onSelect={handleClick}
|
|
||||||
type="button"
|
|
||||||
className={getDropdownMenuItemClassName(className)}
|
|
||||||
title={rest.title ?? rest["aria-label"]}
|
|
||||||
>
|
|
||||||
<MenuItemContent icon={icon} shortcut={shortcut}>
|
|
||||||
{children}
|
|
||||||
</MenuItemContent>
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuPrimitive.Item>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DropdownMenuSubItem;
|
|
||||||
DropdownMenuSubItem.displayName = "DropdownMenuSubItem";
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import React from "react";
|
|
||||||
|
|
||||||
import { ChevronRight } from "../icons";
|
|
||||||
|
|
||||||
import MenuItemContent from "./DropdownMenuItemContent";
|
|
||||||
import { getDropdownMenuItemClassName } from "./common";
|
|
||||||
|
|
||||||
import type { JSX } from "react";
|
|
||||||
|
|
||||||
const DropdownMenuSubTrigger = ({
|
|
||||||
children,
|
|
||||||
icon,
|
|
||||||
className,
|
|
||||||
...rest
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode;
|
|
||||||
icon?: JSX.Element;
|
|
||||||
className?: string;
|
|
||||||
} & React.HTMLAttributes<HTMLDivElement>) => {
|
|
||||||
return (
|
|
||||||
<DropdownMenuPrimitive.SubTrigger className="radix-menu-item dropdown-menu__submenu-trigger">
|
|
||||||
<div
|
|
||||||
{...rest}
|
|
||||||
className={getDropdownMenuItemClassName(className)}
|
|
||||||
title={rest.title ?? rest["aria-label"]}
|
|
||||||
>
|
|
||||||
<MenuItemContent icon={icon}>{children}</MenuItemContent>
|
|
||||||
<div className="dropdown-menu__submenu-trigger-icon">
|
|
||||||
{ChevronRight}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</DropdownMenuPrimitive.SubTrigger>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DropdownMenuSubTrigger;
|
|
||||||
DropdownMenuSubTrigger.displayName = "DropdownMenuSubTrigger";
|
|
||||||
@ -1,7 +1,5 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
||||||
|
|
||||||
import { useDevice } from "../App";
|
import { useDevice } from "../App";
|
||||||
|
|
||||||
const MenuTrigger = ({
|
const MenuTrigger = ({
|
||||||
@ -25,8 +23,7 @@ const MenuTrigger = ({
|
|||||||
},
|
},
|
||||||
).trim();
|
).trim();
|
||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.Trigger
|
<button
|
||||||
data-dropdown-menu-trigger
|
|
||||||
data-prevent-outside-click
|
data-prevent-outside-click
|
||||||
className={classNames}
|
className={classNames}
|
||||||
onClick={onToggle}
|
onClick={onToggle}
|
||||||
@ -36,7 +33,7 @@ const MenuTrigger = ({
|
|||||||
{...rest}
|
{...rest}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</DropdownMenuPrimitive.Trigger>
|
</button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
const getMenuComponent = (component: string) => (children: React.ReactNode) => {
|
export const getMenuTriggerComponent = (children: React.ReactNode) => {
|
||||||
const comp = React.Children.toArray(children).find(
|
const comp = React.Children.toArray(children).find(
|
||||||
(child) =>
|
(child) =>
|
||||||
React.isValidElement(child) &&
|
React.isValidElement(child) &&
|
||||||
@ -8,7 +8,7 @@ const getMenuComponent = (component: string) => (children: React.ReactNode) => {
|
|||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
child?.type.displayName &&
|
child?.type.displayName &&
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
child.type.displayName === component,
|
child.type.displayName === "DropdownMenuTrigger",
|
||||||
);
|
);
|
||||||
if (!comp) {
|
if (!comp) {
|
||||||
return null;
|
return null;
|
||||||
@ -17,11 +17,19 @@ const getMenuComponent = (component: string) => (children: React.ReactNode) => {
|
|||||||
return comp;
|
return comp;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMenuTriggerComponent = getMenuComponent("DropdownMenuTrigger");
|
export const getMenuContentComponent = (children: React.ReactNode) => {
|
||||||
export const getMenuContentComponent = getMenuComponent("DropdownMenuContent");
|
const comp = React.Children.toArray(children).find(
|
||||||
export const getSubMenuTriggerComponent = getMenuComponent(
|
(child) =>
|
||||||
"DropdownMenuSubTrigger",
|
React.isValidElement(child) &&
|
||||||
);
|
typeof child.type !== "string" &&
|
||||||
export const getSubMenuContentComponent = getMenuComponent(
|
//@ts-ignore
|
||||||
"DropdownMenuSubContent",
|
child?.type.displayName &&
|
||||||
|
//@ts-ignore
|
||||||
|
child.type.displayName === "DropdownMenuContent",
|
||||||
);
|
);
|
||||||
|
if (!comp) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
//@ts-ignore
|
||||||
|
return comp;
|
||||||
|
};
|
||||||
|
|||||||
@ -72,15 +72,6 @@ const modifiedTablerIconProps: Opts = {
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
//tabler-icons: chevron-right
|
|
||||||
export const ChevronRight = createIcon(
|
|
||||||
<g strokeWidth="1.5">
|
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
||||||
<polyline points="9 6 15 12 9 18" />
|
|
||||||
</g>,
|
|
||||||
tablerIconProps,
|
|
||||||
);
|
|
||||||
|
|
||||||
// tabler-icons: present
|
// tabler-icons: present
|
||||||
export const PlusPromoIcon = createIcon(
|
export const PlusPromoIcon = createIcon(
|
||||||
<g strokeWidth="1.5">
|
<g strokeWidth="1.5">
|
||||||
@ -127,6 +118,17 @@ export const DotsIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// tabler-icons: dots-horizontal (horizontal equivalent of dots-vertical)
|
||||||
|
export const DotsHorizontalIcon = createIcon(
|
||||||
|
<g strokeWidth="1.5">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M5 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
|
||||||
|
<path d="M12 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
|
||||||
|
<path d="M19 12m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|
||||||
// tabler-icons: pinned
|
// tabler-icons: pinned
|
||||||
export const PinIcon = createIcon(
|
export const PinIcon = createIcon(
|
||||||
<svg strokeWidth="1.5">
|
<svg strokeWidth="1.5">
|
||||||
@ -405,6 +407,19 @@ export const TextIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const TextSizeIcon = createIcon(
|
||||||
|
<g stroke="currentColor" strokeWidth="1.5">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M3 7v-2h13v2" />
|
||||||
|
<path d="M10 5v14" />
|
||||||
|
<path d="M12 19h-4" />
|
||||||
|
<path d="M15 13v-1h6v1" />
|
||||||
|
<path d="M18 12v7" />
|
||||||
|
<path d="M17 19h2" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|
||||||
// modified tabler-icons: photo
|
// modified tabler-icons: photo
|
||||||
export const ImageIcon = createIcon(
|
export const ImageIcon = createIcon(
|
||||||
<g strokeWidth="1.25">
|
<g strokeWidth="1.25">
|
||||||
@ -2279,8 +2294,17 @@ export const elementLinkIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const settingsIcon = createIcon(
|
export const resizeIcon = createIcon(
|
||||||
<g strokeWidth={1.25}>
|
<g strokeWidth={1.5}>
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M4 11v8a1 1 0 0 0 1 1h8m-9 -14v-1a1 1 0 0 1 1 -1h1m5 0h2m5 0h1a1 1 0 0 1 1 1v1m0 5v2m0 5v1a1 1 0 0 1 -1 1h-1" />
|
||||||
|
<path d="M4 12h7a1 1 0 0 1 1 1v7" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const adjustmentsIcon = createIcon(
|
||||||
|
<g strokeWidth={1.5}>
|
||||||
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
<path d="M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
<path d="M14 6m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" />
|
||||||
<path d="M4 6l8 0" />
|
<path d="M4 6l8 0" />
|
||||||
@ -2295,4 +2319,22 @@ export const settingsIcon = createIcon(
|
|||||||
tablerIconProps,
|
tablerIconProps,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const emptyIcon = <div style={{ width: "1rem", height: "1rem" }} />;
|
export const backgroundIcon = createIcon(
|
||||||
|
<g strokeWidth={1}>
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M6 10l4 -4" />
|
||||||
|
<path d="M6 14l8 -8" />
|
||||||
|
<path d="M6 18l12 -12" />
|
||||||
|
<path d="M10 18l8 -8" />
|
||||||
|
<path d="M14 18l4 -4" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const strokeIcon = createIcon(
|
||||||
|
<g strokeWidth={1}>
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<rect x="6" y="6" width="12" height="12" fill="none" />
|
||||||
|
</g>,
|
||||||
|
tablerIconProps,
|
||||||
|
);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
|
import { isMobileOrTablet, MQ_MIN_WIDTH_DESKTOP } from "@excalidraw/common";
|
||||||
|
|
||||||
import { t } from "../../i18n";
|
import { t } from "../../i18n";
|
||||||
import { Button } from "../Button";
|
import { Button } from "../Button";
|
||||||
import { share } from "../icons";
|
import { share } from "../icons";
|
||||||
@ -17,7 +19,8 @@ const LiveCollaborationTrigger = ({
|
|||||||
} & React.ButtonHTMLAttributes<HTMLButtonElement>) => {
|
} & React.ButtonHTMLAttributes<HTMLButtonElement>) => {
|
||||||
const appState = useUIAppState();
|
const appState = useUIAppState();
|
||||||
|
|
||||||
const showIconOnly = appState.width < 830;
|
const showIconOnly =
|
||||||
|
isMobileOrTablet() || appState.width < MQ_MIN_WIDTH_DESKTOP;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@ -9,11 +9,8 @@ import {
|
|||||||
actionLoadScene,
|
actionLoadScene,
|
||||||
actionSaveToActiveFile,
|
actionSaveToActiveFile,
|
||||||
actionShortcuts,
|
actionShortcuts,
|
||||||
actionToggleGridMode,
|
|
||||||
actionToggleObjectsSnapMode,
|
|
||||||
actionToggleSearchMenu,
|
actionToggleSearchMenu,
|
||||||
actionToggleTheme,
|
actionToggleTheme,
|
||||||
actionToggleZenMode,
|
|
||||||
} from "../../actions";
|
} from "../../actions";
|
||||||
import { getShortcutFromShortcutName } from "../../actions/shortcuts";
|
import { getShortcutFromShortcutName } from "../../actions/shortcuts";
|
||||||
import { trackEvent } from "../../analytics";
|
import { trackEvent } from "../../analytics";
|
||||||
@ -26,23 +23,13 @@ import {
|
|||||||
useExcalidrawActionManager,
|
useExcalidrawActionManager,
|
||||||
useExcalidrawElements,
|
useExcalidrawElements,
|
||||||
useAppProps,
|
useAppProps,
|
||||||
useApp,
|
|
||||||
} from "../App";
|
} from "../App";
|
||||||
import { openConfirmModal } from "../OverwriteConfirm/OverwriteConfirmState";
|
import { openConfirmModal } from "../OverwriteConfirm/OverwriteConfirmState";
|
||||||
import Trans from "../Trans";
|
import Trans from "../Trans";
|
||||||
import DropdownMenuItem from "../dropdownMenu/DropdownMenuItem";
|
import DropdownMenuItem from "../dropdownMenu/DropdownMenuItem";
|
||||||
import DropdownMenuItemContentRadio from "../dropdownMenu/DropdownMenuItemContentRadio";
|
import DropdownMenuItemContentRadio from "../dropdownMenu/DropdownMenuItemContentRadio";
|
||||||
import DropdownMenuItemLink from "../dropdownMenu/DropdownMenuItemLink";
|
import DropdownMenuItemLink from "../dropdownMenu/DropdownMenuItemLink";
|
||||||
import DropdownMenuSub from "../dropdownMenu/DropdownMenuSub";
|
import { GithubIcon, DiscordIcon, XBrandIcon } from "../icons";
|
||||||
import { actionToggleViewMode } from "../../actions/actionToggleViewMode";
|
|
||||||
import {
|
|
||||||
GithubIcon,
|
|
||||||
DiscordIcon,
|
|
||||||
XBrandIcon,
|
|
||||||
settingsIcon,
|
|
||||||
checkIcon,
|
|
||||||
emptyIcon,
|
|
||||||
} from "../icons";
|
|
||||||
import {
|
import {
|
||||||
boltIcon,
|
boltIcon,
|
||||||
DeviceDesktopIcon,
|
DeviceDesktopIcon,
|
||||||
@ -326,10 +313,7 @@ export const ChangeCanvasBackground = () => {
|
|||||||
>
|
>
|
||||||
{t("labels.canvasBackground")}
|
{t("labels.canvasBackground")}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div style={{ padding: "0 0.625rem" }}>
|
||||||
style={{ padding: "0 0.625rem" }}
|
|
||||||
id="canvas-bg-color-picker-container"
|
|
||||||
>
|
|
||||||
{actionManager.renderAction("changeViewBackgroundColor")}
|
{actionManager.renderAction("changeViewBackgroundColor")}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -409,73 +393,3 @@ export const LiveCollaborationTrigger = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
LiveCollaborationTrigger.displayName = "LiveCollaborationTrigger";
|
LiveCollaborationTrigger.displayName = "LiveCollaborationTrigger";
|
||||||
|
|
||||||
export const Preferences = ({ children }: { children?: React.ReactNode }) => {
|
|
||||||
const { t } = useI18n();
|
|
||||||
const actionManager = useExcalidrawActionManager();
|
|
||||||
const appState = useUIAppState();
|
|
||||||
const app = useApp();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DropdownMenuSub>
|
|
||||||
<DropdownMenuSub.Trigger icon={settingsIcon}>
|
|
||||||
{t("labels.preferences")}
|
|
||||||
</DropdownMenuSub.Trigger>
|
|
||||||
<DropdownMenuSub.Content className="excalidraw-main-menu-preferences-submenu">
|
|
||||||
<DropdownMenuSub.Item
|
|
||||||
icon={appState.activeTool.locked ? checkIcon : emptyIcon}
|
|
||||||
shortcut={getShortcutFromShortcutName("toolLock")}
|
|
||||||
onSelect={(event) => {
|
|
||||||
app.toggleLock();
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("labels.preferences_toolLock")}
|
|
||||||
</DropdownMenuSub.Item>
|
|
||||||
<DropdownMenuSub.Item
|
|
||||||
icon={appState.objectsSnapModeEnabled ? checkIcon : emptyIcon}
|
|
||||||
shortcut={getShortcutFromShortcutName("objectsSnapMode")}
|
|
||||||
onSelect={(event) => {
|
|
||||||
actionManager.executeAction(actionToggleObjectsSnapMode);
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("buttons.objectsSnapMode")}
|
|
||||||
</DropdownMenuSub.Item>
|
|
||||||
<DropdownMenuSub.Item
|
|
||||||
icon={appState.gridModeEnabled ? checkIcon : emptyIcon}
|
|
||||||
shortcut={getShortcutFromShortcutName("gridMode")}
|
|
||||||
onSelect={(event) => {
|
|
||||||
actionManager.executeAction(actionToggleGridMode);
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("labels.toggleGrid")}
|
|
||||||
</DropdownMenuSub.Item>
|
|
||||||
<DropdownMenuSub.Item
|
|
||||||
icon={appState.zenModeEnabled ? checkIcon : emptyIcon}
|
|
||||||
shortcut={getShortcutFromShortcutName("zenMode")}
|
|
||||||
onSelect={(event) => {
|
|
||||||
actionManager.executeAction(actionToggleZenMode);
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("buttons.zenMode")}
|
|
||||||
</DropdownMenuSub.Item>
|
|
||||||
<DropdownMenuSub.Item
|
|
||||||
icon={appState.viewModeEnabled ? checkIcon : emptyIcon}
|
|
||||||
shortcut={getShortcutFromShortcutName("viewMode")}
|
|
||||||
onSelect={(event) => {
|
|
||||||
actionManager.executeAction(actionToggleViewMode);
|
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("labels.viewMode")}
|
|
||||||
</DropdownMenuSub.Item>
|
|
||||||
{children}
|
|
||||||
</DropdownMenuSub.Content>
|
|
||||||
</DropdownMenuSub>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Preferences.displayName = "Preferences";
|
|
||||||
|
|||||||
@ -2,12 +2,8 @@ import React from "react";
|
|||||||
|
|
||||||
import { composeEventHandlers } from "@excalidraw/common";
|
import { composeEventHandlers } from "@excalidraw/common";
|
||||||
|
|
||||||
import * as Portal from "@radix-ui/react-portal";
|
|
||||||
|
|
||||||
import { useTunnels } from "../../context/tunnels";
|
import { useTunnels } from "../../context/tunnels";
|
||||||
import { useUIAppState } from "../../context/ui-appState";
|
import { useUIAppState } from "../../context/ui-appState";
|
||||||
import DropdownMenuSub from "../dropdownMenu/DropdownMenuSub";
|
|
||||||
|
|
||||||
import { t } from "../../i18n";
|
import { t } from "../../i18n";
|
||||||
import { useDevice, useExcalidrawSetAppState } from "../App";
|
import { useDevice, useExcalidrawSetAppState } from "../App";
|
||||||
import { UserList } from "../UserList";
|
import { UserList } from "../UserList";
|
||||||
@ -40,17 +36,6 @@ const MainMenu = Object.assign(
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<MainMenuTunnel.In>
|
<MainMenuTunnel.In>
|
||||||
{appState.openMenu === "canvas" && device.editor.isMobile && (
|
|
||||||
<Portal.Root
|
|
||||||
style={{
|
|
||||||
backgroundColor: "rgba(18, 18, 18, 0.2)",
|
|
||||||
position: "fixed",
|
|
||||||
inset: "0px",
|
|
||||||
// zIndex: "var(--zIndex-layerUI)",
|
|
||||||
}}
|
|
||||||
onClick={() => setAppState({ openMenu: null })}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<DropdownMenu open={appState.openMenu === "canvas"}>
|
<DropdownMenu open={appState.openMenu === "canvas"}>
|
||||||
<DropdownMenu.Trigger
|
<DropdownMenu.Trigger
|
||||||
onToggle={() => {
|
onToggle={() => {
|
||||||
@ -59,27 +44,15 @@ const MainMenu = Object.assign(
|
|||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
data-testid="main-menu-trigger"
|
data-testid="main-menu-trigger"
|
||||||
aria-label="Main menu"
|
|
||||||
className="main-menu-trigger"
|
className="main-menu-trigger"
|
||||||
>
|
>
|
||||||
{HamburgerMenuIcon}
|
{HamburgerMenuIcon}
|
||||||
</DropdownMenu.Trigger>
|
</DropdownMenu.Trigger>
|
||||||
<DropdownMenu.Content
|
<DropdownMenu.Content
|
||||||
sideOffset={device.editor.isMobile ? 20 : undefined}
|
|
||||||
className="main-menu-content"
|
|
||||||
onClickOutside={onClickOutside}
|
onClickOutside={onClickOutside}
|
||||||
onSelect={composeEventHandlers(onSelect, () => {
|
onSelect={composeEventHandlers(onSelect, () => {
|
||||||
setAppState({ openMenu: null });
|
setAppState({ openMenu: null });
|
||||||
})}
|
})}
|
||||||
collisionPadding={
|
|
||||||
// accounting for
|
|
||||||
// - editor footer on desktop
|
|
||||||
// - toolbar on mobile
|
|
||||||
// we probably don't want the menu to overlay these elements
|
|
||||||
!device.editor.isMobile
|
|
||||||
? { bottom: 90, top: 10 }
|
|
||||||
: { top: 90, bottom: 10 }
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{device.editor.isMobile && appState.collaborators.size > 0 && (
|
{device.editor.isMobile && appState.collaborators.size > 0 && (
|
||||||
@ -105,7 +78,6 @@ const MainMenu = Object.assign(
|
|||||||
ItemCustom: DropdownMenu.ItemCustom,
|
ItemCustom: DropdownMenu.ItemCustom,
|
||||||
Group: DropdownMenu.Group,
|
Group: DropdownMenu.Group,
|
||||||
Separator: DropdownMenu.Separator,
|
Separator: DropdownMenu.Separator,
|
||||||
Sub: DropdownMenuSub,
|
|
||||||
DefaultItems,
|
DefaultItems,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -317,7 +317,7 @@ body.excalidraw-cursor-resize * {
|
|||||||
|
|
||||||
.App-menu_top {
|
.App-menu_top {
|
||||||
grid-template-columns: 1fr 2fr 1fr;
|
grid-template-columns: 1fr 2fr 1fr;
|
||||||
grid-gap: 2rem;
|
grid-gap: 1rem;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
pointer-events: none !important;
|
pointer-events: none !important;
|
||||||
@ -336,6 +336,14 @@ body.excalidraw-cursor-resize * {
|
|||||||
justify-self: flex-start;
|
justify-self: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.selected-shape-actions-container {
|
||||||
|
width: fit-content;
|
||||||
|
|
||||||
|
&--compact {
|
||||||
|
min-width: 48px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.App-menu_top > *:last-child {
|
.App-menu_top > *:last-child {
|
||||||
justify-self: flex-end;
|
justify-self: flex-end;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,7 +144,6 @@
|
|||||||
--color-logo-icon: var(--color-primary);
|
--color-logo-icon: var(--color-primary);
|
||||||
--color-logo-text: #190064;
|
--color-logo-text: #190064;
|
||||||
|
|
||||||
--border-radius-sm: 0.25rem;
|
|
||||||
--border-radius-md: 0.375rem;
|
--border-radius-md: 0.375rem;
|
||||||
--border-radius-lg: 0.5rem;
|
--border-radius-lg: 0.5rem;
|
||||||
|
|
||||||
|
|||||||
@ -96,6 +96,8 @@ export const getMimeType = (blob: Blob | string): string => {
|
|||||||
return MIME_TYPES.jpg;
|
return MIME_TYPES.jpg;
|
||||||
} else if (/\.svg$/.test(name)) {
|
} else if (/\.svg$/.test(name)) {
|
||||||
return MIME_TYPES.svg;
|
return MIME_TYPES.svg;
|
||||||
|
} else if (/\.excalidrawlib$/.test(name)) {
|
||||||
|
return MIME_TYPES.excalidrawlib;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
};
|
};
|
||||||
@ -389,23 +391,18 @@ export const ImageURLToFile = async (
|
|||||||
throw new Error("Error: unsupported file type", { cause: "UNSUPPORTED" });
|
throw new Error("Error: unsupported file type", { cause: "UNSUPPORTED" });
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFileFromEvent = async (
|
|
||||||
event: React.DragEvent<HTMLDivElement>,
|
|
||||||
) => {
|
|
||||||
const file = event.dataTransfer.files.item(0);
|
|
||||||
const fileHandle = await getFileHandle(event);
|
|
||||||
|
|
||||||
return { file: file ? await normalizeFile(file) : null, fileHandle };
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getFileHandle = async (
|
export const getFileHandle = async (
|
||||||
event: React.DragEvent<HTMLDivElement>,
|
event: DragEvent | React.DragEvent | DataTransferItem,
|
||||||
): Promise<FileSystemHandle | null> => {
|
): Promise<FileSystemHandle | null> => {
|
||||||
if (nativeFileSystemSupported) {
|
if (nativeFileSystemSupported) {
|
||||||
try {
|
try {
|
||||||
const item = event.dataTransfer.items[0];
|
const dataTransferItem =
|
||||||
|
event instanceof DataTransferItem
|
||||||
|
? event
|
||||||
|
: (event as DragEvent).dataTransfer?.items?.[0];
|
||||||
|
|
||||||
const handle: FileSystemHandle | null =
|
const handle: FileSystemHandle | null =
|
||||||
(await (item as any).getAsFileSystemHandle()) || null;
|
(await (dataTransferItem as any).getAsFileSystemHandle()) || null;
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@ -1,11 +1,26 @@
|
|||||||
import { arrayToMap, easeOut, THEME } from "@excalidraw/common";
|
import { arrayToMap, easeOut, THEME } from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
computeBoundTextPosition,
|
computeBoundTextPosition,
|
||||||
|
distanceToElement,
|
||||||
|
doBoundsIntersect,
|
||||||
getBoundTextElement,
|
getBoundTextElement,
|
||||||
|
getElementBounds,
|
||||||
|
getFreedrawOutlineAsSegments,
|
||||||
|
getFreedrawOutlinePoints,
|
||||||
intersectElementWithLineSegment,
|
intersectElementWithLineSegment,
|
||||||
|
isArrowElement,
|
||||||
|
isFreeDrawElement,
|
||||||
|
isLineElement,
|
||||||
isPointInElement,
|
isPointInElement,
|
||||||
} from "@excalidraw/element";
|
} from "@excalidraw/element";
|
||||||
import { lineSegment, pointFrom } from "@excalidraw/math";
|
import {
|
||||||
|
lineSegment,
|
||||||
|
lineSegmentsDistance,
|
||||||
|
pointFrom,
|
||||||
|
polygon,
|
||||||
|
polygonIncludesPointNonZero,
|
||||||
|
} from "@excalidraw/math";
|
||||||
|
|
||||||
import { getElementsInGroup } from "@excalidraw/element";
|
import { getElementsInGroup } from "@excalidraw/element";
|
||||||
|
|
||||||
@ -13,6 +28,8 @@ import { shouldTestInside } from "@excalidraw/element";
|
|||||||
import { hasBoundTextElement, isBoundToContainer } from "@excalidraw/element";
|
import { hasBoundTextElement, isBoundToContainer } from "@excalidraw/element";
|
||||||
import { getBoundTextElementId } from "@excalidraw/element";
|
import { getBoundTextElementId } from "@excalidraw/element";
|
||||||
|
|
||||||
|
import type { Bounds } from "@excalidraw/element";
|
||||||
|
|
||||||
import type { GlobalPoint, LineSegment } from "@excalidraw/math/types";
|
import type { GlobalPoint, LineSegment } from "@excalidraw/math/types";
|
||||||
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
import type { ElementsMap, ExcalidrawElement } from "@excalidraw/element/types";
|
||||||
|
|
||||||
@ -96,6 +113,7 @@ export class EraserTrail extends AnimatedTrail {
|
|||||||
pathSegment,
|
pathSegment,
|
||||||
element,
|
element,
|
||||||
candidateElementsMap,
|
candidateElementsMap,
|
||||||
|
this.app.state.zoom.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (intersects) {
|
if (intersects) {
|
||||||
@ -131,6 +149,7 @@ export class EraserTrail extends AnimatedTrail {
|
|||||||
pathSegment,
|
pathSegment,
|
||||||
element,
|
element,
|
||||||
candidateElementsMap,
|
candidateElementsMap,
|
||||||
|
this.app.state.zoom.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (intersects) {
|
if (intersects) {
|
||||||
@ -180,8 +199,33 @@ const eraserTest = (
|
|||||||
pathSegment: LineSegment<GlobalPoint>,
|
pathSegment: LineSegment<GlobalPoint>,
|
||||||
element: ExcalidrawElement,
|
element: ExcalidrawElement,
|
||||||
elementsMap: ElementsMap,
|
elementsMap: ElementsMap,
|
||||||
|
zoom: number,
|
||||||
): boolean => {
|
): boolean => {
|
||||||
const lastPoint = pathSegment[1];
|
const lastPoint = pathSegment[1];
|
||||||
|
|
||||||
|
// PERF: Do a quick bounds intersection test first because it's cheap
|
||||||
|
const threshold = isFreeDrawElement(element) ? 15 : element.strokeWidth / 2;
|
||||||
|
const segmentBounds = [
|
||||||
|
Math.min(pathSegment[0][0], pathSegment[1][0]) - threshold,
|
||||||
|
Math.min(pathSegment[0][1], pathSegment[1][1]) - threshold,
|
||||||
|
Math.max(pathSegment[0][0], pathSegment[1][0]) + threshold,
|
||||||
|
Math.max(pathSegment[0][1], pathSegment[1][1]) + threshold,
|
||||||
|
] as Bounds;
|
||||||
|
const origElementBounds = getElementBounds(element, elementsMap);
|
||||||
|
const elementBounds: Bounds = [
|
||||||
|
origElementBounds[0] - threshold,
|
||||||
|
origElementBounds[1] - threshold,
|
||||||
|
origElementBounds[2] + threshold,
|
||||||
|
origElementBounds[3] + threshold,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!doBoundsIntersect(segmentBounds, elementBounds)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// There are shapes where the inner area should trigger erasing
|
||||||
|
// even though the eraser path segment doesn't intersect with or
|
||||||
|
// get close to the shape's stroke
|
||||||
if (
|
if (
|
||||||
shouldTestInside(element) &&
|
shouldTestInside(element) &&
|
||||||
isPointInElement(lastPoint, element, elementsMap)
|
isPointInElement(lastPoint, element, elementsMap)
|
||||||
@ -189,6 +233,50 @@ const eraserTest = (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Freedraw elements are tested for erasure by measuring the distance
|
||||||
|
// of the eraser path and the freedraw shape outline lines to a tolerance
|
||||||
|
// which offers a good visual precision at various zoom levels
|
||||||
|
if (isFreeDrawElement(element)) {
|
||||||
|
const outlinePoints = getFreedrawOutlinePoints(element);
|
||||||
|
const strokeSegments = getFreedrawOutlineAsSegments(
|
||||||
|
element,
|
||||||
|
outlinePoints,
|
||||||
|
elementsMap,
|
||||||
|
);
|
||||||
|
const tolerance = Math.max(2.25, 5 / zoom); // NOTE: Visually fine-tuned approximation
|
||||||
|
|
||||||
|
for (const seg of strokeSegments) {
|
||||||
|
if (lineSegmentsDistance(seg, pathSegment) <= tolerance) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const poly = polygon(
|
||||||
|
...(outlinePoints.map(([x, y]) =>
|
||||||
|
pointFrom<GlobalPoint>(element.x + x, element.y + y),
|
||||||
|
) as GlobalPoint[]),
|
||||||
|
);
|
||||||
|
|
||||||
|
// PERF: Check only one point of the eraser segment. If the eraser segment
|
||||||
|
// start is inside the closed freedraw shape, the other point is either also
|
||||||
|
// inside or the eraser segment will intersect the shape outline anyway
|
||||||
|
if (polygonIncludesPointNonZero(pathSegment[0], poly)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} else if (
|
||||||
|
isArrowElement(element) ||
|
||||||
|
(isLineElement(element) && !element.polygon)
|
||||||
|
) {
|
||||||
|
const tolerance = Math.max(
|
||||||
|
element.strokeWidth,
|
||||||
|
(element.strokeWidth * 2) / zoom,
|
||||||
|
);
|
||||||
|
|
||||||
|
return distanceToElement(element, elementsMap, lastPoint) <= tolerance;
|
||||||
|
}
|
||||||
|
|
||||||
const boundTextElement = getBoundTextElement(element, elementsMap);
|
const boundTextElement = getBoundTextElement(element, elementsMap);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
112
packages/excalidraw/hooks/useTextEditorFocus.ts
Normal file
112
packages/excalidraw/hooks/useTextEditorFocus.ts
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
import { useState, useCallback } from "react";
|
||||||
|
|
||||||
|
// Utility type for caret position
|
||||||
|
export type CaretPosition = {
|
||||||
|
start: number;
|
||||||
|
end: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Utility function to get text editor element
|
||||||
|
const getTextEditor = (): HTMLTextAreaElement | null => {
|
||||||
|
return document.querySelector(".excalidraw-wysiwyg") as HTMLTextAreaElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Utility functions for caret position management
|
||||||
|
export const saveCaretPosition = (): CaretPosition | null => {
|
||||||
|
const textEditor = getTextEditor();
|
||||||
|
if (textEditor) {
|
||||||
|
return {
|
||||||
|
start: textEditor.selectionStart,
|
||||||
|
end: textEditor.selectionEnd,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const restoreCaretPosition = (position: CaretPosition | null): void => {
|
||||||
|
setTimeout(() => {
|
||||||
|
const textEditor = getTextEditor();
|
||||||
|
if (textEditor) {
|
||||||
|
textEditor.focus();
|
||||||
|
if (position) {
|
||||||
|
textEditor.selectionStart = position.start;
|
||||||
|
textEditor.selectionEnd = position.end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const withCaretPositionPreservation = (
|
||||||
|
callback: () => void,
|
||||||
|
isCompactMode: boolean,
|
||||||
|
isEditingText: boolean,
|
||||||
|
onPreventClose?: () => void,
|
||||||
|
): void => {
|
||||||
|
// Prevent popover from closing in compact mode
|
||||||
|
if (isCompactMode && onPreventClose) {
|
||||||
|
onPreventClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save caret position if editing text
|
||||||
|
const savedPosition =
|
||||||
|
isCompactMode && isEditingText ? saveCaretPosition() : null;
|
||||||
|
|
||||||
|
// Execute the callback
|
||||||
|
callback();
|
||||||
|
|
||||||
|
// Restore caret position if needed
|
||||||
|
if (isCompactMode && isEditingText) {
|
||||||
|
restoreCaretPosition(savedPosition);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Hook for managing text editor caret position with state
|
||||||
|
export const useTextEditorFocus = () => {
|
||||||
|
const [savedCaretPosition, setSavedCaretPosition] =
|
||||||
|
useState<CaretPosition | null>(null);
|
||||||
|
|
||||||
|
const saveCaretPositionToState = useCallback(() => {
|
||||||
|
const position = saveCaretPosition();
|
||||||
|
setSavedCaretPosition(position);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const restoreCaretPositionFromState = useCallback(() => {
|
||||||
|
setTimeout(() => {
|
||||||
|
const textEditor = getTextEditor();
|
||||||
|
if (textEditor) {
|
||||||
|
textEditor.focus();
|
||||||
|
if (savedCaretPosition) {
|
||||||
|
textEditor.selectionStart = savedCaretPosition.start;
|
||||||
|
textEditor.selectionEnd = savedCaretPosition.end;
|
||||||
|
setSavedCaretPosition(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}, [savedCaretPosition]);
|
||||||
|
|
||||||
|
const clearSavedPosition = useCallback(() => {
|
||||||
|
setSavedCaretPosition(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
saveCaretPosition: saveCaretPositionToState,
|
||||||
|
restoreCaretPosition: restoreCaretPositionFromState,
|
||||||
|
clearSavedPosition,
|
||||||
|
hasSavedPosition: !!savedCaretPosition,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Utility function to temporarily disable text editor blur
|
||||||
|
export const temporarilyDisableTextEditorBlur = (
|
||||||
|
duration: number = 100,
|
||||||
|
): void => {
|
||||||
|
const textEditor = getTextEditor();
|
||||||
|
if (textEditor) {
|
||||||
|
const originalOnBlur = textEditor.onblur;
|
||||||
|
textEditor.onblur = null;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
textEditor.onblur = originalOnBlur;
|
||||||
|
}, duration);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -171,9 +171,7 @@
|
|||||||
"linkToElement": "Link to object",
|
"linkToElement": "Link to object",
|
||||||
"wrapSelectionInFrame": "Wrap selection in frame",
|
"wrapSelectionInFrame": "Wrap selection in frame",
|
||||||
"tab": "Tab",
|
"tab": "Tab",
|
||||||
"shapeSwitch": "Switch shape",
|
"shapeSwitch": "Switch shape"
|
||||||
"preferences": "Preferences",
|
|
||||||
"preferences_toolLock": "Tool lock"
|
|
||||||
},
|
},
|
||||||
"elementLink": {
|
"elementLink": {
|
||||||
"title": "Link to object",
|
"title": "Link to object",
|
||||||
|
|||||||
@ -81,13 +81,11 @@
|
|||||||
"@braintree/sanitize-url": "6.0.2",
|
"@braintree/sanitize-url": "6.0.2",
|
||||||
"@excalidraw/common": "0.18.0",
|
"@excalidraw/common": "0.18.0",
|
||||||
"@excalidraw/element": "0.18.0",
|
"@excalidraw/element": "0.18.0",
|
||||||
"@excalidraw/laser-pointer": "1.3.1",
|
|
||||||
"@excalidraw/math": "0.18.0",
|
"@excalidraw/math": "0.18.0",
|
||||||
|
"@excalidraw/laser-pointer": "1.3.1",
|
||||||
"@excalidraw/mermaid-to-excalidraw": "1.1.3",
|
"@excalidraw/mermaid-to-excalidraw": "1.1.3",
|
||||||
"@excalidraw/random-username": "1.1.0",
|
"@excalidraw/random-username": "1.1.0",
|
||||||
"@radix-ui/react-dropdown-menu": "2.1.16",
|
|
||||||
"@radix-ui/react-popover": "1.1.6",
|
"@radix-ui/react-popover": "1.1.6",
|
||||||
"@radix-ui/react-portal": "1.1.9",
|
|
||||||
"@radix-ui/react-tabs": "1.1.3",
|
"@radix-ui/react-tabs": "1.1.3",
|
||||||
"browser-fs-access": "0.29.1",
|
"browser-fs-access": "0.29.1",
|
||||||
"canvas-roundrect-polyfill": "0.0.1",
|
"canvas-roundrect-polyfill": "0.0.1",
|
||||||
@ -99,8 +97,8 @@
|
|||||||
"image-blob-reduce": "3.0.1",
|
"image-blob-reduce": "3.0.1",
|
||||||
"jotai": "2.11.0",
|
"jotai": "2.11.0",
|
||||||
"jotai-scope": "0.7.2",
|
"jotai-scope": "0.7.2",
|
||||||
"lodash.debounce": "4.0.8",
|
|
||||||
"lodash.throttle": "4.1.1",
|
"lodash.throttle": "4.1.1",
|
||||||
|
"lodash.debounce": "4.0.8",
|
||||||
"nanoid": "3.3.3",
|
"nanoid": "3.3.3",
|
||||||
"open-color": "1.9.1",
|
"open-color": "1.9.1",
|
||||||
"pako": "2.0.3",
|
"pako": "2.0.3",
|
||||||
|
|||||||
@ -981,6 +981,7 @@ exports[`contextMenu element > right-clicking on a group should select whole gro
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1172,6 +1173,7 @@ exports[`contextMenu element > selecting 'Add to library' in context menu adds e
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": {
|
"toast": {
|
||||||
@ -1384,6 +1386,7 @@ exports[`contextMenu element > selecting 'Bring forward' in context menu brings
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1713,6 +1716,7 @@ exports[`contextMenu element > selecting 'Bring to front' in context menu brings
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2042,6 +2046,7 @@ exports[`contextMenu element > selecting 'Copy styles' in context menu copies st
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": {
|
"toast": {
|
||||||
@ -2252,6 +2257,7 @@ exports[`contextMenu element > selecting 'Delete' in context menu deletes elemen
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2493,6 +2499,7 @@ exports[`contextMenu element > selecting 'Duplicate' in context menu duplicates
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2794,6 +2801,7 @@ exports[`contextMenu element > selecting 'Group selection' in context menu group
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3159,6 +3167,7 @@ exports[`contextMenu element > selecting 'Paste styles' in context menu pastes s
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": {
|
"toast": {
|
||||||
@ -3650,6 +3659,7 @@ exports[`contextMenu element > selecting 'Send backward' in context menu sends e
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3971,6 +3981,7 @@ exports[`contextMenu element > selecting 'Send to back' in context menu sends el
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4295,6 +4306,7 @@ exports[`contextMenu element > selecting 'Ungroup selection' in context menu ung
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5578,6 +5590,7 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -6795,6 +6808,7 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7724,6 +7738,7 @@ exports[`contextMenu element > shows context menu for canvas > [end of test] app
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8721,6 +8736,7 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9713,6 +9729,7 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
|
|||||||
@ -688,6 +688,7 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
aria-haspopup="dialog"
|
aria-haspopup="dialog"
|
||||||
aria-label="Canvas background"
|
aria-label="Canvas background"
|
||||||
class="color-picker__button active-color properties-trigger has-outline"
|
class="color-picker__button active-color properties-trigger has-outline"
|
||||||
|
data-openpopup="canvasBackground"
|
||||||
data-state="closed"
|
data-state="closed"
|
||||||
style="--swatch-color: #ffffff;"
|
style="--swatch-color: #ffffff;"
|
||||||
title="Show background color picker"
|
title="Show background color picker"
|
||||||
|
|||||||
@ -100,6 +100,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -714,6 +715,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1197,6 +1199,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1559,6 +1562,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1924,6 +1928,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2184,6 +2189,7 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2625,6 +2631,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2926,6 +2933,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3243,6 +3251,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3535,6 +3544,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3819,6 +3829,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4052,6 +4063,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4307,6 +4319,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4576,6 +4589,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4803,6 +4817,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5030,6 +5045,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5275,6 +5291,7 @@ exports[`history > multiplayer undo/redo > conflicts in bound text elements and
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5529,6 +5546,7 @@ exports[`history > multiplayer undo/redo > conflicts in frames and their childre
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5784,6 +5802,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -6111,6 +6130,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -6539,6 +6559,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -6917,6 +6938,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7216,6 +7238,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7530,6 +7553,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7758,6 +7782,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8108,6 +8133,7 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8464,6 +8490,7 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8862,6 +8889,7 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9149,6 +9177,7 @@ exports[`history > multiplayer undo/redo > should not let remote changes to inte
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9411,6 +9440,7 @@ exports[`history > multiplayer undo/redo > should not override remote changes on
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9674,6 +9704,7 @@ exports[`history > multiplayer undo/redo > should not override remote changes on
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9905,6 +9936,7 @@ exports[`history > multiplayer undo/redo > should override remotely added groups
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -10199,6 +10231,7 @@ exports[`history > multiplayer undo/redo > should override remotely added points
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -10544,6 +10577,7 @@ exports[`history > multiplayer undo/redo > should redistribute deltas when eleme
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -10781,6 +10815,7 @@ exports[`history > multiplayer undo/redo > should redraw arrows on undo > [end o
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11226,6 +11261,7 @@ exports[`history > multiplayer undo/redo > should update history entries after r
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11482,6 +11518,7 @@ exports[`history > singleplayer undo/redo > remounting undo/redo buttons should
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11717,6 +11754,7 @@ exports[`history > singleplayer undo/redo > should clear the redo stack on eleme
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11950,6 +11988,7 @@ exports[`history > singleplayer undo/redo > should create entry when selecting f
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -12291,7 +12330,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
|
|||||||
"editingGroupId": null,
|
"editingGroupId": null,
|
||||||
"editingTextElement": null,
|
"editingTextElement": null,
|
||||||
"elementsToHighlight": null,
|
"elementsToHighlight": null,
|
||||||
"errorMessage": "Couldn't load invalid file",
|
"errorMessage": null,
|
||||||
"exportBackground": true,
|
"exportBackground": true,
|
||||||
"exportEmbedScene": false,
|
"exportEmbedScene": false,
|
||||||
"exportScale": 1,
|
"exportScale": 1,
|
||||||
@ -12356,6 +12395,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -12534,10 +12574,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
|
|||||||
"openMenu": null,
|
"openMenu": null,
|
||||||
"openPopup": null,
|
"openPopup": null,
|
||||||
"openSidebar": null,
|
"openSidebar": null,
|
||||||
"originSnapOffset": {
|
"originSnapOffset": null,
|
||||||
"x": 0,
|
|
||||||
"y": 0,
|
|
||||||
},
|
|
||||||
"pasteDialog": {
|
"pasteDialog": {
|
||||||
"data": null,
|
"data": null,
|
||||||
"shown": false,
|
"shown": false,
|
||||||
@ -12564,6 +12601,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on e
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -12759,6 +12797,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"searchMatches": null,
|
"searchMatches": null,
|
||||||
"selectedElementIds": {
|
"selectedElementIds": {
|
||||||
"id0": true,
|
"id0": true,
|
||||||
|
"id1": true,
|
||||||
},
|
},
|
||||||
"selectedElementsAreBeingDragged": false,
|
"selectedElementsAreBeingDragged": false,
|
||||||
"selectedGroupIds": {},
|
"selectedGroupIds": {},
|
||||||
@ -12772,6 +12811,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -12793,7 +12833,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"boundElements": null,
|
"boundElements": null,
|
||||||
"crop": null,
|
"crop": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fileId": "fileId",
|
"fileId": "id2",
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@ -12816,16 +12856,53 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"updated": 1,
|
"updated": 1,
|
||||||
"version": 5,
|
"version": 7,
|
||||||
"width": 318,
|
"width": 318,
|
||||||
"x": -159,
|
"x": -212,
|
||||||
"y": "-167.50000",
|
"y": "-167.50000",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] number of elements 1`] = `1`;
|
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] element 1 1`] = `
|
||||||
|
{
|
||||||
|
"angle": 0,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"boundElements": null,
|
||||||
|
"crop": null,
|
||||||
|
"customData": undefined,
|
||||||
|
"fileId": "id3",
|
||||||
|
"fillStyle": "solid",
|
||||||
|
"frameId": null,
|
||||||
|
"groupIds": [],
|
||||||
|
"height": 77,
|
||||||
|
"id": "id1",
|
||||||
|
"index": "a1",
|
||||||
|
"isDeleted": false,
|
||||||
|
"link": null,
|
||||||
|
"locked": false,
|
||||||
|
"opacity": 100,
|
||||||
|
"roughness": 1,
|
||||||
|
"roundness": null,
|
||||||
|
"scale": [
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"status": "pending",
|
||||||
|
"strokeColor": "transparent",
|
||||||
|
"strokeStyle": "solid",
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"type": "image",
|
||||||
|
"updated": 1,
|
||||||
|
"version": 7,
|
||||||
|
"width": 56,
|
||||||
|
"x": 156,
|
||||||
|
"y": "-167.50000",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] number of renders 1`] = `7`;
|
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] number of elements 1`] = `2`;
|
||||||
|
|
||||||
|
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] number of renders 1`] = `8`;
|
||||||
|
|
||||||
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] redo stack 1`] = `[]`;
|
exports[`history > singleplayer undo/redo > should create new history entry on image drag&drop > [end of test] redo stack 1`] = `[]`;
|
||||||
|
|
||||||
@ -12837,6 +12914,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"deleted": {
|
"deleted": {
|
||||||
"selectedElementIds": {
|
"selectedElementIds": {
|
||||||
"id0": true,
|
"id0": true,
|
||||||
|
"id1": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
@ -12854,7 +12932,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"boundElements": null,
|
"boundElements": null,
|
||||||
"crop": null,
|
"crop": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fileId": "fileId",
|
"fileId": "id2",
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
@ -12875,20 +12953,58 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"version": 5,
|
"version": 7,
|
||||||
"width": 318,
|
"width": 318,
|
||||||
"x": -159,
|
"x": -212,
|
||||||
"y": "-167.50000",
|
"y": "-167.50000",
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"isDeleted": true,
|
"isDeleted": true,
|
||||||
"version": 4,
|
"version": 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"id1": {
|
||||||
|
"deleted": {
|
||||||
|
"angle": 0,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"boundElements": null,
|
||||||
|
"crop": null,
|
||||||
|
"customData": undefined,
|
||||||
|
"fileId": "id3",
|
||||||
|
"fillStyle": "solid",
|
||||||
|
"frameId": null,
|
||||||
|
"groupIds": [],
|
||||||
|
"height": 77,
|
||||||
|
"index": "a1",
|
||||||
|
"isDeleted": false,
|
||||||
|
"link": null,
|
||||||
|
"locked": false,
|
||||||
|
"opacity": 100,
|
||||||
|
"roughness": 1,
|
||||||
|
"roundness": null,
|
||||||
|
"scale": [
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"status": "pending",
|
||||||
|
"strokeColor": "transparent",
|
||||||
|
"strokeStyle": "solid",
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"type": "image",
|
||||||
|
"version": 7,
|
||||||
|
"width": 56,
|
||||||
|
"x": 156,
|
||||||
|
"y": "-167.50000",
|
||||||
|
},
|
||||||
|
"inserted": {
|
||||||
|
"isDeleted": true,
|
||||||
|
"version": 6,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"updated": {},
|
"updated": {},
|
||||||
},
|
},
|
||||||
"id": "id4",
|
"id": "id7",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
@ -12964,10 +13080,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"openMenu": null,
|
"openMenu": null,
|
||||||
"openPopup": null,
|
"openPopup": null,
|
||||||
"openSidebar": null,
|
"openSidebar": null,
|
||||||
"originSnapOffset": {
|
"originSnapOffset": null,
|
||||||
"x": 0,
|
|
||||||
"y": 0,
|
|
||||||
},
|
|
||||||
"pasteDialog": {
|
"pasteDialog": {
|
||||||
"data": null,
|
"data": null,
|
||||||
"shown": false,
|
"shown": false,
|
||||||
@ -12981,6 +13094,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"searchMatches": null,
|
"searchMatches": null,
|
||||||
"selectedElementIds": {
|
"selectedElementIds": {
|
||||||
"id0": true,
|
"id0": true,
|
||||||
|
"id1": true,
|
||||||
},
|
},
|
||||||
"selectedElementsAreBeingDragged": false,
|
"selectedElementsAreBeingDragged": false,
|
||||||
"selectedGroupIds": {},
|
"selectedGroupIds": {},
|
||||||
@ -12994,6 +13108,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13015,11 +13130,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"boundElements": null,
|
"boundElements": null,
|
||||||
"crop": null,
|
"crop": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fileId": "fileId",
|
"fileId": "id2",
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
"height": 77,
|
"height": 335,
|
||||||
"id": "id0",
|
"id": "id0",
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
@ -13038,16 +13153,53 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"updated": 1,
|
"updated": 1,
|
||||||
"version": 5,
|
"version": 7,
|
||||||
"width": 56,
|
"width": 318,
|
||||||
"x": -28,
|
"x": -212,
|
||||||
"y": "-38.50000",
|
"y": "-167.50000",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] number of elements 1`] = `1`;
|
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] element 1 1`] = `
|
||||||
|
{
|
||||||
|
"angle": 0,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"boundElements": null,
|
||||||
|
"crop": null,
|
||||||
|
"customData": undefined,
|
||||||
|
"fileId": "id3",
|
||||||
|
"fillStyle": "solid",
|
||||||
|
"frameId": null,
|
||||||
|
"groupIds": [],
|
||||||
|
"height": 77,
|
||||||
|
"id": "id1",
|
||||||
|
"index": "a1",
|
||||||
|
"isDeleted": false,
|
||||||
|
"link": null,
|
||||||
|
"locked": false,
|
||||||
|
"opacity": 100,
|
||||||
|
"roughness": 1,
|
||||||
|
"roundness": null,
|
||||||
|
"scale": [
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"status": "pending",
|
||||||
|
"strokeColor": "transparent",
|
||||||
|
"strokeStyle": "solid",
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"type": "image",
|
||||||
|
"updated": 1,
|
||||||
|
"version": 7,
|
||||||
|
"width": 56,
|
||||||
|
"x": 156,
|
||||||
|
"y": "-167.50000",
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] number of renders 1`] = `7`;
|
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] number of elements 1`] = `2`;
|
||||||
|
|
||||||
|
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] number of renders 1`] = `8`;
|
||||||
|
|
||||||
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] redo stack 1`] = `[]`;
|
exports[`history > singleplayer undo/redo > should create new history entry on image paste > [end of test] redo stack 1`] = `[]`;
|
||||||
|
|
||||||
@ -13059,6 +13211,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"deleted": {
|
"deleted": {
|
||||||
"selectedElementIds": {
|
"selectedElementIds": {
|
||||||
"id0": true,
|
"id0": true,
|
||||||
|
"id1": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
@ -13076,11 +13229,11 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"boundElements": null,
|
"boundElements": null,
|
||||||
"crop": null,
|
"crop": null,
|
||||||
"customData": undefined,
|
"customData": undefined,
|
||||||
"fileId": "fileId",
|
"fileId": "id2",
|
||||||
"fillStyle": "solid",
|
"fillStyle": "solid",
|
||||||
"frameId": null,
|
"frameId": null,
|
||||||
"groupIds": [],
|
"groupIds": [],
|
||||||
"height": 77,
|
"height": 335,
|
||||||
"index": "a0",
|
"index": "a0",
|
||||||
"isDeleted": false,
|
"isDeleted": false,
|
||||||
"link": null,
|
"link": null,
|
||||||
@ -13097,20 +13250,58 @@ exports[`history > singleplayer undo/redo > should create new history entry on i
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"version": 5,
|
"version": 7,
|
||||||
"width": 56,
|
"width": 318,
|
||||||
"x": -28,
|
"x": -212,
|
||||||
"y": "-38.50000",
|
"y": "-167.50000",
|
||||||
},
|
},
|
||||||
"inserted": {
|
"inserted": {
|
||||||
"isDeleted": true,
|
"isDeleted": true,
|
||||||
"version": 4,
|
"version": 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"id1": {
|
||||||
|
"deleted": {
|
||||||
|
"angle": 0,
|
||||||
|
"backgroundColor": "transparent",
|
||||||
|
"boundElements": null,
|
||||||
|
"crop": null,
|
||||||
|
"customData": undefined,
|
||||||
|
"fileId": "id3",
|
||||||
|
"fillStyle": "solid",
|
||||||
|
"frameId": null,
|
||||||
|
"groupIds": [],
|
||||||
|
"height": 77,
|
||||||
|
"index": "a1",
|
||||||
|
"isDeleted": false,
|
||||||
|
"link": null,
|
||||||
|
"locked": false,
|
||||||
|
"opacity": 100,
|
||||||
|
"roughness": 1,
|
||||||
|
"roundness": null,
|
||||||
|
"scale": [
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"status": "pending",
|
||||||
|
"strokeColor": "transparent",
|
||||||
|
"strokeStyle": "solid",
|
||||||
|
"strokeWidth": 2,
|
||||||
|
"type": "image",
|
||||||
|
"version": 7,
|
||||||
|
"width": 56,
|
||||||
|
"x": 156,
|
||||||
|
"y": "-167.50000",
|
||||||
|
},
|
||||||
|
"inserted": {
|
||||||
|
"isDeleted": true,
|
||||||
|
"version": 6,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"updated": {},
|
"updated": {},
|
||||||
},
|
},
|
||||||
"id": "id4",
|
"id": "id7",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
@ -13214,6 +13405,7 @@ exports[`history > singleplayer undo/redo > should create new history entry on s
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13456,6 +13648,7 @@ exports[`history > singleplayer undo/redo > should disable undo/redo buttons whe
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13691,6 +13884,7 @@ exports[`history > singleplayer undo/redo > should end up with no history entry
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13926,6 +14120,7 @@ exports[`history > singleplayer undo/redo > should iterate through the history w
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14171,6 +14366,7 @@ exports[`history > singleplayer undo/redo > should not clear the redo stack on s
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14501,6 +14697,7 @@ exports[`history > singleplayer undo/redo > should not collapse when applying co
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14671,6 +14868,7 @@ exports[`history > singleplayer undo/redo > should not end up with history entry
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14951,6 +15149,7 @@ exports[`history > singleplayer undo/redo > should not end up with history entry
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -15212,6 +15411,7 @@ exports[`history > singleplayer undo/redo > should not modify anything on unrela
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -15364,6 +15564,7 @@ exports[`history > singleplayer undo/redo > should not override appstate changes
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -15643,6 +15844,7 @@ exports[`history > singleplayer undo/redo > should support appstate name or view
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -15804,6 +16006,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -16507,6 +16710,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -17140,6 +17344,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -17771,6 +17976,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -18491,6 +18697,7 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -19240,6 +19447,7 @@ exports[`history > singleplayer undo/redo > should support changes in elements'
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -19720,6 +19928,7 @@ exports[`history > singleplayer undo/redo > should support duplication of groups
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -20224,6 +20433,7 @@ exports[`history > singleplayer undo/redo > should support element creation, del
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -20683,6 +20893,7 @@ exports[`history > singleplayer undo/redo > should support linear element creati
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
|
|||||||
@ -108,6 +108,7 @@ exports[`given element A and group of elements B and given both are selected whe
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -534,6 +535,7 @@ exports[`given element A and group of elements B and given both are selected whe
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -939,6 +941,7 @@ exports[`regression tests > Cmd/Ctrl-click exclusively select element under poin
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1503,6 +1506,7 @@ exports[`regression tests > Drags selected element when hitting only bounding bo
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -1713,6 +1717,7 @@ exports[`regression tests > adjusts z order when grouping > [end of test] appSta
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2092,6 +2097,7 @@ exports[`regression tests > alt-drag duplicates an element > [end of test] appSt
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2333,6 +2339,7 @@ exports[`regression tests > arrow keys > [end of test] appState 1`] = `
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2513,6 +2520,7 @@ exports[`regression tests > can drag element that covers another element, while
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -2834,6 +2842,7 @@ exports[`regression tests > change the properties of a shape > [end of test] app
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3089,6 +3098,7 @@ exports[`regression tests > click on an element and drag it > [dragged] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3328,6 +3338,7 @@ exports[`regression tests > click on an element and drag it > [end of test] appS
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3562,6 +3573,7 @@ exports[`regression tests > click to select a shape > [end of test] appState 1`]
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -3819,6 +3831,7 @@ exports[`regression tests > click-drag to select a group > [end of test] appStat
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4130,6 +4143,7 @@ exports[`regression tests > deleting last but one element in editing group shoul
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4591,6 +4605,7 @@ exports[`regression tests > deselects group of selected elements on pointer down
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -4844,6 +4859,7 @@ exports[`regression tests > deselects group of selected elements on pointer up w
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5145,6 +5161,7 @@ exports[`regression tests > deselects selected element on pointer down when poin
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5323,6 +5340,7 @@ exports[`regression tests > deselects selected element, on pointer up, when clic
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5521,6 +5539,7 @@ exports[`regression tests > double click to edit a group > [end of test] appStat
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -5916,6 +5935,7 @@ exports[`regression tests > drags selected elements from point inside common bou
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -6205,6 +6225,7 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7064,6 +7085,7 @@ exports[`regression tests > given a group of selected elements with an element t
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7396,6 +7418,7 @@ exports[`regression tests > given a selected element A and a not selected elemen
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7672,6 +7695,7 @@ exports[`regression tests > given selected element A with lower z-index than uns
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -7905,6 +7929,7 @@ exports[`regression tests > given selected element A with lower z-index than uns
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8141,6 +8166,7 @@ exports[`regression tests > key 2 selects rectangle tool > [end of test] appStat
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8319,6 +8345,7 @@ exports[`regression tests > key 3 selects diamond tool > [end of test] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8497,6 +8524,7 @@ exports[`regression tests > key 4 selects ellipse tool > [end of test] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8702,6 +8730,7 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -8930,6 +8959,7 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9127,6 +9157,7 @@ exports[`regression tests > key 7 selects freedraw tool > [end of test] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9350,6 +9381,7 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9551,6 +9583,7 @@ exports[`regression tests > key d selects diamond tool > [end of test] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9756,6 +9789,7 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -9955,6 +9989,7 @@ exports[`regression tests > key o selects ellipse tool > [end of test] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -10131,6 +10166,7 @@ exports[`regression tests > key p selects freedraw tool > [end of test] appState
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -10327,6 +10363,7 @@ exports[`regression tests > key r selects rectangle tool > [end of test] appStat
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -10513,6 +10550,7 @@ exports[`regression tests > make a group and duplicate it > [end of test] appSta
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11036,6 +11074,7 @@ exports[`regression tests > noop interaction after undo shouldn't create history
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11310,6 +11349,7 @@ exports[`regression tests > pinch-to-zoom works > [end of test] appState 1`] = `
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11433,6 +11473,7 @@ exports[`regression tests > shift click on selected element should deselect it o
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11635,6 +11676,7 @@ exports[`regression tests > shift-click to multiselect, then drag > [end of test
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -11954,6 +11996,7 @@ exports[`regression tests > should group elements and ungroup them > [end of tes
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -12385,6 +12428,7 @@ exports[`regression tests > single-clicking on a subgroup of a selected group sh
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13014,6 +13058,7 @@ exports[`regression tests > spacebar + drag scrolls the canvas > [end of test] a
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13139,6 +13184,7 @@ exports[`regression tests > supports nested groups > [end of test] appState 1`]
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -13797,6 +13843,7 @@ exports[`regression tests > switches from group of selected elements to another
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14133,6 +14180,7 @@ exports[`regression tests > switches selected element on pointer down > [end of
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14363,6 +14411,7 @@ exports[`regression tests > two-finger scroll works > [end of test] appState 1`]
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14486,6 +14535,7 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14874,6 +14924,7 @@ exports[`regression tests > updates fontSize & fontFamily appState > [end of tes
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
@ -14998,6 +15049,7 @@ exports[`regression tests > zoom hotkeys > [end of test] appState 1`] = `
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
|
|||||||
@ -35,8 +35,10 @@ describe("appState", () => {
|
|||||||
expect(h.state.viewBackgroundColor).toBe("#F00");
|
expect(h.state.viewBackgroundColor).toBe("#F00");
|
||||||
});
|
});
|
||||||
|
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob(
|
{
|
||||||
|
kind: "file",
|
||||||
|
file: new Blob(
|
||||||
[
|
[
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: EXPORT_DATA_TYPES.excalidraw,
|
type: EXPORT_DATA_TYPES.excalidraw,
|
||||||
@ -48,7 +50,8 @@ describe("appState", () => {
|
|||||||
],
|
],
|
||||||
{ type: MIME_TYPES.json },
|
{ type: MIME_TYPES.json },
|
||||||
),
|
),
|
||||||
);
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]);
|
expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]);
|
||||||
|
|||||||
@ -1,18 +1,13 @@
|
|||||||
import { queryByText, queryByTestId } from "@testing-library/react";
|
import { queryByText, queryByTestId } from "@testing-library/react";
|
||||||
|
import React from "react";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
|
|
||||||
import { THEME } from "@excalidraw/common";
|
import { THEME } from "@excalidraw/common";
|
||||||
|
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import { Excalidraw, Footer } from "..";
|
import { Excalidraw, Footer, MainMenu } from "../index";
|
||||||
import MainMenu from "../components/main-menu/MainMenu";
|
|
||||||
|
|
||||||
import {
|
import { fireEvent, GlobalTestState, toggleMenu, render } from "./test-utils";
|
||||||
render,
|
|
||||||
togglePopover,
|
|
||||||
fireEvent,
|
|
||||||
GlobalTestState,
|
|
||||||
} from "./test-utils";
|
|
||||||
|
|
||||||
const { h } = window;
|
const { h } = window;
|
||||||
|
|
||||||
@ -20,7 +15,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
const menu = document.querySelector(".dropdown-menu");
|
const menu = document.querySelector(".dropdown-menu");
|
||||||
if (menu) {
|
if (menu) {
|
||||||
togglePopover("Main menu");
|
toggleMenu(document.querySelector(".excalidraw")!);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -141,7 +136,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
<Excalidraw UIOptions={undefined} />,
|
<Excalidraw UIOptions={undefined} />,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "dropdown-menu")).toMatchSnapshot();
|
expect(queryByTestId(container, "dropdown-menu")).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -150,7 +145,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
<Excalidraw UIOptions={{ canvasActions: { clearCanvas: false } }} />,
|
<Excalidraw UIOptions={{ canvasActions: { clearCanvas: false } }} />,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "clear-canvas-button")).toBeNull();
|
expect(queryByTestId(container, "clear-canvas-button")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -159,7 +154,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
<Excalidraw UIOptions={{ canvasActions: { export: false } }} />,
|
<Excalidraw UIOptions={{ canvasActions: { export: false } }} />,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "json-export-button")).toBeNull();
|
expect(queryByTestId(container, "json-export-button")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -168,7 +163,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
<Excalidraw UIOptions={{ canvasActions: { saveAsImage: false } }} />,
|
<Excalidraw UIOptions={{ canvasActions: { saveAsImage: false } }} />,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "image-export-button")).toBeNull();
|
expect(queryByTestId(container, "image-export-button")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -187,7 +182,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "save-as-button")).toBeNull();
|
expect(queryByTestId(container, "save-as-button")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -198,7 +193,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "save-button")).toBeNull();
|
expect(queryByTestId(container, "save-button")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -209,7 +204,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "canvas-background-label")).toBeNull();
|
expect(queryByTestId(container, "canvas-background-label")).toBeNull();
|
||||||
expect(queryByTestId(container, "canvas-background-picker")).toBeNull();
|
expect(queryByTestId(container, "canvas-background-picker")).toBeNull();
|
||||||
});
|
});
|
||||||
@ -225,7 +220,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
</Excalidraw>,
|
</Excalidraw>,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "canvas-background-label")).toBeNull();
|
expect(queryByTestId(container, "canvas-background-label")).toBeNull();
|
||||||
expect(queryByTestId(container, "canvas-background-picker")).toBeNull();
|
expect(queryByTestId(container, "canvas-background-picker")).toBeNull();
|
||||||
});
|
});
|
||||||
@ -235,7 +230,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
<Excalidraw UIOptions={{ canvasActions: { toggleTheme: false } }} />,
|
<Excalidraw UIOptions={{ canvasActions: { toggleTheme: false } }} />,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "toggle-dark-mode")).toBeNull();
|
expect(queryByTestId(container, "toggle-dark-mode")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -256,8 +251,8 @@ describe("<Excalidraw/>", () => {
|
|||||||
</Excalidraw>,
|
</Excalidraw>,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
|
toggleMenu(container);
|
||||||
// load button shouldn't be rendered since `UIActions.canvasActions.loadScene` is `false`
|
// load button shouldn't be rendered since `UIActions.canvasActions.loadScene` is `false`
|
||||||
togglePopover("Main menu");
|
|
||||||
expect(queryByTestId(container, "load-button")).toBeNull();
|
expect(queryByTestId(container, "load-button")).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -268,7 +263,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
const { container } = await render(<Excalidraw />);
|
const { container } = await render(<Excalidraw />);
|
||||||
expect(h.state.theme).toBe(THEME.LIGHT);
|
expect(h.state.theme).toBe(THEME.LIGHT);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
||||||
expect(darkModeToggle).toBeTruthy();
|
expect(darkModeToggle).toBeTruthy();
|
||||||
});
|
});
|
||||||
@ -278,7 +273,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
|
|
||||||
expect(h.state.theme).toBe(THEME.DARK);
|
expect(h.state.theme).toBe(THEME.DARK);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "toggle-dark-mode")).toBe(null);
|
expect(queryByTestId(container, "toggle-dark-mode")).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -291,7 +286,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
);
|
);
|
||||||
expect(h.state.theme).toBe(THEME.DARK);
|
expect(h.state.theme).toBe(THEME.DARK);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
||||||
expect(darkModeToggle).toBeTruthy();
|
expect(darkModeToggle).toBeTruthy();
|
||||||
});
|
});
|
||||||
@ -305,7 +300,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
);
|
);
|
||||||
expect(h.state.theme).toBe(THEME.DARK);
|
expect(h.state.theme).toBe(THEME.DARK);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
const darkModeToggle = queryByTestId(container, "toggle-dark-mode");
|
||||||
expect(darkModeToggle).toBe(null);
|
expect(darkModeToggle).toBe(null);
|
||||||
});
|
});
|
||||||
@ -315,7 +310,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
it("should allow editing name", async () => {
|
it("should allow editing name", async () => {
|
||||||
const { container } = await render(<Excalidraw />);
|
const { container } = await render(<Excalidraw />);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
fireEvent.click(queryByTestId(container, "image-export-button")!);
|
fireEvent.click(queryByTestId(container, "image-export-button")!);
|
||||||
const textInput: HTMLInputElement | null = document.querySelector(
|
const textInput: HTMLInputElement | null = document.querySelector(
|
||||||
".ImageExportModal .ImageExportModal__preview__filename .TextInput",
|
".ImageExportModal .ImageExportModal__preview__filename .TextInput",
|
||||||
@ -328,7 +323,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
const name = "test";
|
const name = "test";
|
||||||
const { container } = await render(<Excalidraw name={name} />);
|
const { container } = await render(<Excalidraw name={name} />);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
await fireEvent.click(queryByTestId(container, "image-export-button")!);
|
await fireEvent.click(queryByTestId(container, "image-export-button")!);
|
||||||
const textInput = document.querySelector(
|
const textInput = document.querySelector(
|
||||||
".ImageExportModal .ImageExportModal__preview__filename .TextInput",
|
".ImageExportModal .ImageExportModal__preview__filename .TextInput",
|
||||||
@ -380,7 +375,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
</Excalidraw>,
|
</Excalidraw>,
|
||||||
);
|
);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
expect(queryByTestId(container, "dropdown-menu")).toMatchSnapshot();
|
expect(queryByTestId(container, "dropdown-menu")).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -399,7 +394,7 @@ describe("<Excalidraw/>", () => {
|
|||||||
|
|
||||||
const { container } = await render(<CustomExcalidraw />);
|
const { container } = await render(<CustomExcalidraw />);
|
||||||
//open menu
|
//open menu
|
||||||
togglePopover("Main menu");
|
toggleMenu(container);
|
||||||
|
|
||||||
expect(h.state.theme).toBe(THEME.LIGHT);
|
expect(h.state.theme).toBe(THEME.LIGHT);
|
||||||
|
|
||||||
|
|||||||
@ -57,7 +57,7 @@ describe("export", () => {
|
|||||||
blob: pngBlob,
|
blob: pngBlob,
|
||||||
metadata: serializeAsJSON(testElements, h.state, {}, "local"),
|
metadata: serializeAsJSON(testElements, h.state, {}, "local"),
|
||||||
});
|
});
|
||||||
await API.drop(pngBlobEmbedded);
|
await API.drop([{ kind: "file", file: pngBlobEmbedded }]);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
@ -94,7 +94,12 @@ describe("export", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("import embedded png (legacy v1)", async () => {
|
it("import embedded png (legacy v1)", async () => {
|
||||||
await API.drop(await API.loadFile("./fixtures/test_embedded_v1.png"));
|
await API.drop([
|
||||||
|
{
|
||||||
|
kind: "file",
|
||||||
|
file: await API.loadFile("./fixtures/test_embedded_v1.png"),
|
||||||
|
},
|
||||||
|
]);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ type: "text", text: "test" }),
|
expect.objectContaining({ type: "text", text: "test" }),
|
||||||
@ -103,7 +108,12 @@ describe("export", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("import embedded png (v2)", async () => {
|
it("import embedded png (v2)", async () => {
|
||||||
await API.drop(await API.loadFile("./fixtures/smiley_embedded_v2.png"));
|
await API.drop([
|
||||||
|
{
|
||||||
|
kind: "file",
|
||||||
|
file: await API.loadFile("./fixtures/smiley_embedded_v2.png"),
|
||||||
|
},
|
||||||
|
]);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ type: "text", text: "😀" }),
|
expect.objectContaining({ type: "text", text: "😀" }),
|
||||||
@ -112,7 +122,12 @@ describe("export", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("import embedded svg (legacy v1)", async () => {
|
it("import embedded svg (legacy v1)", async () => {
|
||||||
await API.drop(await API.loadFile("./fixtures/test_embedded_v1.svg"));
|
await API.drop([
|
||||||
|
{
|
||||||
|
kind: "file",
|
||||||
|
file: await API.loadFile("./fixtures/test_embedded_v1.svg"),
|
||||||
|
},
|
||||||
|
]);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ type: "text", text: "test" }),
|
expect.objectContaining({ type: "text", text: "test" }),
|
||||||
@ -121,7 +136,12 @@ describe("export", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("import embedded svg (v2)", async () => {
|
it("import embedded svg (v2)", async () => {
|
||||||
await API.drop(await API.loadFile("./fixtures/smiley_embedded_v2.svg"));
|
await API.drop([
|
||||||
|
{
|
||||||
|
kind: "file",
|
||||||
|
file: await API.loadFile("./fixtures/smiley_embedded_v2.svg"),
|
||||||
|
},
|
||||||
|
]);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
expect.objectContaining({ type: "text", text: "😀" }),
|
expect.objectContaining({ type: "text", text: "😀" }),
|
||||||
|
|||||||
9
packages/excalidraw/tests/fixtures/constants.ts
vendored
Normal file
9
packages/excalidraw/tests/fixtures/constants.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
export const DEER_IMAGE_DIMENSIONS = {
|
||||||
|
width: 318,
|
||||||
|
height: 335,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SMILEY_IMAGE_DIMENSIONS = {
|
||||||
|
width: 56,
|
||||||
|
height: 77,
|
||||||
|
};
|
||||||
@ -25,6 +25,7 @@ import { Excalidraw } from "../index";
|
|||||||
// Importing to spy on it and mock the implementation (mocking does not work with simple vi.mock for some reason)
|
// Importing to spy on it and mock the implementation (mocking does not work with simple vi.mock for some reason)
|
||||||
import * as blobModule from "../data/blob";
|
import * as blobModule from "../data/blob";
|
||||||
|
|
||||||
|
import { SMILEY_IMAGE_DIMENSIONS } from "./fixtures/constants";
|
||||||
import { API } from "./helpers/api";
|
import { API } from "./helpers/api";
|
||||||
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
import { UI, Pointer, Keyboard } from "./helpers/ui";
|
||||||
import {
|
import {
|
||||||
@ -744,11 +745,6 @@ describe("freedraw", () => {
|
|||||||
//image
|
//image
|
||||||
//TODO: currently there is no test for pixel colors at flipped positions.
|
//TODO: currently there is no test for pixel colors at flipped positions.
|
||||||
describe("image", () => {
|
describe("image", () => {
|
||||||
const smileyImageDimensions = {
|
|
||||||
width: 56,
|
|
||||||
height: 77,
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// it's necessary to specify the height in order to calculate natural dimensions of the image
|
// it's necessary to specify the height in order to calculate natural dimensions of the image
|
||||||
h.state.height = 1000;
|
h.state.height = 1000;
|
||||||
@ -756,8 +752,8 @@ describe("image", () => {
|
|||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
mockHTMLImageElement(
|
mockHTMLImageElement(
|
||||||
smileyImageDimensions.width,
|
SMILEY_IMAGE_DIMENSIONS.width,
|
||||||
smileyImageDimensions.height,
|
SMILEY_IMAGE_DIMENSIONS.height,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -478,33 +478,43 @@ export class API {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
static drop = async (blob: Blob) => {
|
static drop = async (items: ({kind: "string", value: string, type: string} | {kind: "file", file: File | Blob, type?: string })[]) => {
|
||||||
const fileDropEvent = createEvent.drop(GlobalTestState.interactiveCanvas);
|
|
||||||
const text = await new Promise<string>((resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = () => {
|
|
||||||
resolve(reader.result as string);
|
|
||||||
};
|
|
||||||
reader.readAsText(blob);
|
|
||||||
} catch (error: any) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const files = [blob] as File[] & { item: (index: number) => File };
|
const fileDropEvent = createEvent.drop(GlobalTestState.interactiveCanvas);
|
||||||
|
|
||||||
|
const dataTransferFileItems = items.filter(i => i.kind === "file") as {kind: "file", file: File | Blob, type: string }[];
|
||||||
|
|
||||||
|
const files = dataTransferFileItems.map(item => item.file) as File[] & { item: (index: number) => File };
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/FileList/item
|
||||||
files.item = (index: number) => files[index];
|
files.item = (index: number) => files[index];
|
||||||
|
|
||||||
Object.defineProperty(fileDropEvent, "dataTransfer", {
|
Object.defineProperty(fileDropEvent, "dataTransfer", {
|
||||||
value: {
|
value: {
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/files
|
||||||
files,
|
files,
|
||||||
getData: (type: string) => {
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/items
|
||||||
if (type === blob.type || type === "text") {
|
items: items.map((item, idx) => {
|
||||||
return text;
|
if (item.kind === "string") {
|
||||||
|
return {
|
||||||
|
kind: "string",
|
||||||
|
type: item.type,
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsString
|
||||||
|
getAsString: (cb: (text: string) => any) => cb(item.value),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return "";
|
return {
|
||||||
|
kind: "file",
|
||||||
|
type: item.type || item.file.type,
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFile
|
||||||
|
getAsFile: () => item.file,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/getData
|
||||||
|
getData: (type: string) => {
|
||||||
|
return items.find((item) => item.type === "string" && item.type === type) || "";
|
||||||
},
|
},
|
||||||
types: [blob.type],
|
// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types
|
||||||
|
types: Array.from(new Set(items.map((item) => item.kind === "file" ? "Files" : item.type))),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
Object.defineProperty(fileDropEvent, "clientX", {
|
Object.defineProperty(fileDropEvent, "clientX", {
|
||||||
|
|||||||
6
packages/excalidraw/tests/helpers/constants.ts
Normal file
6
packages/excalidraw/tests/helpers/constants.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export const INITIALIZED_IMAGE_PROPS = {
|
||||||
|
type: "image",
|
||||||
|
fileId: expect.any(String),
|
||||||
|
x: expect.toBeNonNaNNumber(),
|
||||||
|
y: expect.toBeNonNaNNumber(),
|
||||||
|
};
|
||||||
@ -58,3 +58,35 @@ export const mockHTMLImageElement = (
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Mocks for multiple HTMLImageElements (dimensions are assigned in the order of image initialization)
|
||||||
|
export const mockMultipleHTMLImageElements = (
|
||||||
|
sizes: (readonly [number, number])[],
|
||||||
|
) => {
|
||||||
|
const _sizes = [...sizes];
|
||||||
|
|
||||||
|
vi.stubGlobal(
|
||||||
|
"Image",
|
||||||
|
class extends Image {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
const size = _sizes.shift();
|
||||||
|
if (!size) {
|
||||||
|
throw new Error("Insufficient sizes");
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(this, "naturalWidth", {
|
||||||
|
value: size[0],
|
||||||
|
});
|
||||||
|
Object.defineProperty(this, "naturalHeight", {
|
||||||
|
value: size[1],
|
||||||
|
});
|
||||||
|
|
||||||
|
queueMicrotask(() => {
|
||||||
|
this.onload?.({} as Event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|||||||
@ -47,42 +47,43 @@ class DataTransferItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataTransferList {
|
class DataTransferItemList extends Array<DataTransferItem> {
|
||||||
items: DataTransferItem[] = [];
|
|
||||||
|
|
||||||
add(data: string | File, type: string = ""): void {
|
add(data: string | File, type: string = ""): void {
|
||||||
if (typeof data === "string") {
|
if (typeof data === "string") {
|
||||||
this.items.push(new DataTransferItem("string", type, data));
|
this.push(new DataTransferItem("string", type, data));
|
||||||
} else if (data instanceof File) {
|
} else if (data instanceof File) {
|
||||||
this.items.push(new DataTransferItem("file", type, data));
|
this.push(new DataTransferItem("file", type, data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(): void {
|
clear(): void {
|
||||||
this.items = [];
|
this.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataTransfer {
|
class DataTransfer {
|
||||||
public items: DataTransferList = new DataTransferList();
|
public items: DataTransferItemList = new DataTransferItemList();
|
||||||
private _types: Record<string, string> = {};
|
|
||||||
|
|
||||||
get files() {
|
get files() {
|
||||||
return this.items.items
|
return this.items
|
||||||
.filter((item) => item.kind === "file")
|
.filter((item) => item.kind === "file")
|
||||||
.map((item) => item.getAsFile()!);
|
.map((item) => item.getAsFile()!);
|
||||||
}
|
}
|
||||||
|
|
||||||
add(data: string | File, type: string = ""): void {
|
add(data: string | File, type: string = ""): void {
|
||||||
|
if (typeof data === "string") {
|
||||||
this.items.add(data, type);
|
this.items.add(data, type);
|
||||||
|
} else {
|
||||||
|
this.items.add(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setData(type: string, value: string) {
|
setData(type: string, value: string) {
|
||||||
this._types[type] = value;
|
this.items.add(value, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
getData(type: string) {
|
getData(type: string) {
|
||||||
return this._types[type] || "";
|
return this.items.find((item) => item.type === type)?.data || "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX,
|
DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX,
|
||||||
DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
|
DEFAULT_ELEMENT_STROKE_COLOR_INDEX,
|
||||||
reseed,
|
reseed,
|
||||||
|
randomId,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import "@excalidraw/utils/test-utils";
|
import "@excalidraw/utils/test-utils";
|
||||||
@ -58,9 +59,13 @@ import { createPasteEvent } from "../clipboard";
|
|||||||
|
|
||||||
import * as blobModule from "../data/blob";
|
import * as blobModule from "../data/blob";
|
||||||
|
|
||||||
|
import {
|
||||||
|
DEER_IMAGE_DIMENSIONS,
|
||||||
|
SMILEY_IMAGE_DIMENSIONS,
|
||||||
|
} from "./fixtures/constants";
|
||||||
import { API } from "./helpers/api";
|
import { API } from "./helpers/api";
|
||||||
import { Keyboard, Pointer, UI } from "./helpers/ui";
|
import { Keyboard, Pointer, UI } from "./helpers/ui";
|
||||||
import { mockHTMLImageElement } from "./helpers/mocks";
|
import { INITIALIZED_IMAGE_PROPS } from "./helpers/constants";
|
||||||
import {
|
import {
|
||||||
GlobalTestState,
|
GlobalTestState,
|
||||||
act,
|
act,
|
||||||
@ -71,6 +76,7 @@ import {
|
|||||||
checkpointHistory,
|
checkpointHistory,
|
||||||
unmountComponent,
|
unmountComponent,
|
||||||
} from "./test-utils";
|
} from "./test-utils";
|
||||||
|
import { setupImageTest as _setupImageTest } from "./image.test";
|
||||||
|
|
||||||
import type { AppState } from "../types";
|
import type { AppState } from "../types";
|
||||||
|
|
||||||
@ -123,7 +129,9 @@ describe("history", () => {
|
|||||||
const generateIdSpy = vi.spyOn(blobModule, "generateIdFromFile");
|
const generateIdSpy = vi.spyOn(blobModule, "generateIdFromFile");
|
||||||
const resizeFileSpy = vi.spyOn(blobModule, "resizeImageFile");
|
const resizeFileSpy = vi.spyOn(blobModule, "resizeImageFile");
|
||||||
|
|
||||||
generateIdSpy.mockImplementation(() => Promise.resolve("fileId" as FileId));
|
generateIdSpy.mockImplementation(() =>
|
||||||
|
Promise.resolve(randomId() as FileId),
|
||||||
|
);
|
||||||
resizeFileSpy.mockImplementation((file: File) => Promise.resolve(file));
|
resizeFileSpy.mockImplementation((file: File) => Promise.resolve(file));
|
||||||
|
|
||||||
Object.assign(document, {
|
Object.assign(document, {
|
||||||
@ -560,8 +568,10 @@ describe("history", () => {
|
|||||||
expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]),
|
expect(h.elements).toEqual([expect.objectContaining({ id: "A" })]),
|
||||||
);
|
);
|
||||||
|
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob(
|
{
|
||||||
|
kind: "file",
|
||||||
|
file: new Blob(
|
||||||
[
|
[
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: EXPORT_DATA_TYPES.excalidraw,
|
type: EXPORT_DATA_TYPES.excalidraw,
|
||||||
@ -574,7 +584,8 @@ describe("history", () => {
|
|||||||
],
|
],
|
||||||
{ type: MIME_TYPES.json },
|
{ type: MIME_TYPES.json },
|
||||||
),
|
),
|
||||||
);
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
await waitFor(() => expect(API.getUndoStack().length).toBe(1));
|
await waitFor(() => expect(API.getUndoStack().length).toBe(1));
|
||||||
expect(h.state.viewBackgroundColor).toBe("#000");
|
expect(h.state.viewBackgroundColor).toBe("#000");
|
||||||
@ -612,89 +623,17 @@ describe("history", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create new history entry on image drag&drop", async () => {
|
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
|
||||||
|
|
||||||
// it's necessary to specify the height in order to calculate natural dimensions of the image
|
|
||||||
h.state.height = 1000;
|
|
||||||
|
|
||||||
const deerImageDimensions = {
|
|
||||||
width: 318,
|
|
||||||
height: 335,
|
|
||||||
};
|
|
||||||
|
|
||||||
mockHTMLImageElement(
|
|
||||||
deerImageDimensions.width,
|
|
||||||
deerImageDimensions.height,
|
|
||||||
);
|
|
||||||
|
|
||||||
await API.drop(await API.loadFile("./fixtures/deer.png"));
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
...deerImageDimensions,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// need to check that delta actually contains initialized image element (with fileId & natural dimensions)
|
|
||||||
expect(
|
|
||||||
Object.values(h.history.undoStack[0].elements.removed)[0].deleted,
|
|
||||||
).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
...deerImageDimensions,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
Keyboard.undo();
|
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
isDeleted: true,
|
|
||||||
...deerImageDimensions,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Keyboard.redo();
|
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
isDeleted: false,
|
|
||||||
...deerImageDimensions,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should create new history entry on embeddable link drag&drop", async () => {
|
it("should create new history entry on embeddable link drag&drop", async () => {
|
||||||
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
await render(<Excalidraw handleKeyboardGlobally={true} />);
|
||||||
|
|
||||||
const link = "https://www.youtube.com/watch?v=gkGMXY0wekg";
|
const link = "https://www.youtube.com/watch?v=gkGMXY0wekg";
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob([link], {
|
{
|
||||||
|
kind: "string",
|
||||||
|
value: link,
|
||||||
type: MIME_TYPES.text,
|
type: MIME_TYPES.text,
|
||||||
}),
|
},
|
||||||
);
|
]);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
@ -730,83 +669,95 @@ describe("history", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const setupImageTest = () =>
|
||||||
|
_setupImageTest([DEER_IMAGE_DIMENSIONS, SMILEY_IMAGE_DIMENSIONS]);
|
||||||
|
|
||||||
|
const assertImageTest = async () => {
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
|
|
||||||
|
// need to check that delta actually contains initialized image elements (with fileId & natural dimensions)
|
||||||
|
expect(
|
||||||
|
Object.values(h.history.undoStack[0].elements.removed).map(
|
||||||
|
(val) => val.deleted,
|
||||||
|
),
|
||||||
|
).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
...DEER_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
...SMILEY_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
Keyboard.undo();
|
||||||
|
expect(API.getUndoStack().length).toBe(0);
|
||||||
|
expect(API.getRedoStack().length).toBe(1);
|
||||||
|
expect(h.elements).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
isDeleted: true,
|
||||||
|
...DEER_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
isDeleted: true,
|
||||||
|
...SMILEY_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
Keyboard.redo();
|
||||||
|
expect(API.getUndoStack().length).toBe(1);
|
||||||
|
expect(API.getRedoStack().length).toBe(0);
|
||||||
|
expect(h.elements).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
isDeleted: false,
|
||||||
|
...DEER_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
isDeleted: false,
|
||||||
|
...SMILEY_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should create new history entry on image drag&drop", async () => {
|
||||||
|
await setupImageTest();
|
||||||
|
|
||||||
|
await API.drop(
|
||||||
|
(
|
||||||
|
await Promise.all([
|
||||||
|
API.loadFile("./fixtures/deer.png"),
|
||||||
|
API.loadFile("./fixtures/smiley.png"),
|
||||||
|
])
|
||||||
|
).map((file) => ({
|
||||||
|
kind: "file",
|
||||||
|
file,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
await assertImageTest();
|
||||||
|
});
|
||||||
|
|
||||||
it("should create new history entry on image paste", async () => {
|
it("should create new history entry on image paste", async () => {
|
||||||
await render(
|
await setupImageTest();
|
||||||
<Excalidraw autoFocus={true} handleKeyboardGlobally={true} />,
|
|
||||||
);
|
|
||||||
|
|
||||||
// it's necessary to specify the height in order to calculate natural dimensions of the image
|
|
||||||
h.state.height = 1000;
|
|
||||||
|
|
||||||
const smileyImageDimensions = {
|
|
||||||
width: 56,
|
|
||||||
height: 77,
|
|
||||||
};
|
|
||||||
|
|
||||||
mockHTMLImageElement(
|
|
||||||
smileyImageDimensions.width,
|
|
||||||
smileyImageDimensions.height,
|
|
||||||
);
|
|
||||||
|
|
||||||
document.dispatchEvent(
|
document.dispatchEvent(
|
||||||
createPasteEvent({
|
createPasteEvent({
|
||||||
files: [await API.loadFile("./fixtures/smiley_embedded_v2.png")],
|
files: await Promise.all([
|
||||||
|
API.loadFile("./fixtures/deer.png"),
|
||||||
|
API.loadFile("./fixtures/smiley.png"),
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
await waitFor(() => {
|
await assertImageTest();
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
...smileyImageDimensions,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
// need to check that delta actually contains initialized image element (with fileId & natural dimensions)
|
|
||||||
expect(
|
|
||||||
Object.values(h.history.undoStack[0].elements.removed)[0].deleted,
|
|
||||||
).toEqual(
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
...smileyImageDimensions,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
Keyboard.undo();
|
|
||||||
expect(API.getUndoStack().length).toBe(0);
|
|
||||||
expect(API.getRedoStack().length).toBe(1);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
isDeleted: true,
|
|
||||||
...smileyImageDimensions,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
Keyboard.redo();
|
|
||||||
expect(API.getUndoStack().length).toBe(1);
|
|
||||||
expect(API.getRedoStack().length).toBe(0);
|
|
||||||
expect(h.elements).toEqual([
|
|
||||||
expect.objectContaining({
|
|
||||||
type: "image",
|
|
||||||
fileId: expect.any(String),
|
|
||||||
x: expect.toBeNonNaNNumber(),
|
|
||||||
y: expect.toBeNonNaNNumber(),
|
|
||||||
isDeleted: false,
|
|
||||||
...smileyImageDimensions,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create new history entry on embeddable link paste", async () => {
|
it("should create new history entry on embeddable link paste", async () => {
|
||||||
|
|||||||
115
packages/excalidraw/tests/image.test.tsx
Normal file
115
packages/excalidraw/tests/image.test.tsx
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import { randomId, reseed } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import type { FileId } from "@excalidraw/element/types";
|
||||||
|
|
||||||
|
import * as blobModule from "../data/blob";
|
||||||
|
import * as filesystemModule from "../data/filesystem";
|
||||||
|
import { Excalidraw } from "../index";
|
||||||
|
import { createPasteEvent } from "../clipboard";
|
||||||
|
|
||||||
|
import { API } from "./helpers/api";
|
||||||
|
import { mockMultipleHTMLImageElements } from "./helpers/mocks";
|
||||||
|
import { UI } from "./helpers/ui";
|
||||||
|
import { GlobalTestState, render, waitFor } from "./test-utils";
|
||||||
|
import {
|
||||||
|
DEER_IMAGE_DIMENSIONS,
|
||||||
|
SMILEY_IMAGE_DIMENSIONS,
|
||||||
|
} from "./fixtures/constants";
|
||||||
|
import { INITIALIZED_IMAGE_PROPS } from "./helpers/constants";
|
||||||
|
|
||||||
|
const { h } = window;
|
||||||
|
|
||||||
|
export const setupImageTest = async (
|
||||||
|
sizes: { width: number; height: number }[],
|
||||||
|
) => {
|
||||||
|
await render(<Excalidraw autoFocus={true} handleKeyboardGlobally={true} />);
|
||||||
|
|
||||||
|
h.state.height = 1000;
|
||||||
|
|
||||||
|
mockMultipleHTMLImageElements(sizes.map((size) => [size.width, size.height]));
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("image insertion", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
vi.unstubAllGlobals();
|
||||||
|
|
||||||
|
reseed(7);
|
||||||
|
|
||||||
|
const generateIdSpy = vi.spyOn(blobModule, "generateIdFromFile");
|
||||||
|
const resizeFileSpy = vi.spyOn(blobModule, "resizeImageFile");
|
||||||
|
|
||||||
|
generateIdSpy.mockImplementation(() =>
|
||||||
|
Promise.resolve(randomId() as FileId),
|
||||||
|
);
|
||||||
|
resizeFileSpy.mockImplementation((file: File) => Promise.resolve(file));
|
||||||
|
|
||||||
|
Object.assign(document, {
|
||||||
|
elementFromPoint: () => GlobalTestState.canvas,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const setup = () =>
|
||||||
|
setupImageTest([DEER_IMAGE_DIMENSIONS, SMILEY_IMAGE_DIMENSIONS]);
|
||||||
|
|
||||||
|
const assert = async () => {
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(h.elements).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
...DEER_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
...INITIALIZED_IMAGE_PROPS,
|
||||||
|
...SMILEY_IMAGE_DIMENSIONS,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
// Not placed on top of each other
|
||||||
|
const dimensionsSet = new Set(h.elements.map((el) => `${el.x}-${el.y}`));
|
||||||
|
expect(dimensionsSet.size).toEqual(h.elements.length);
|
||||||
|
};
|
||||||
|
|
||||||
|
it("should eventually initialize all dropped images", async () => {
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
const files = await Promise.all([
|
||||||
|
API.loadFile("./fixtures/deer.png"),
|
||||||
|
API.loadFile("./fixtures/smiley.png"),
|
||||||
|
]);
|
||||||
|
await API.drop(files.map((file) => ({ kind: "file", file })));
|
||||||
|
|
||||||
|
await assert();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should eventually initialize all pasted images", async () => {
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
document.dispatchEvent(
|
||||||
|
createPasteEvent({
|
||||||
|
files: await Promise.all([
|
||||||
|
API.loadFile("./fixtures/deer.png"),
|
||||||
|
API.loadFile("./fixtures/smiley.png"),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await assert();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should eventually initialize all images added through image tool", async () => {
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
const fileOpenSpy = vi.spyOn(filesystemModule, "fileOpen");
|
||||||
|
fileOpenSpy.mockImplementation(
|
||||||
|
async () =>
|
||||||
|
await Promise.all([
|
||||||
|
API.loadFile("./fixtures/deer.png"),
|
||||||
|
API.loadFile("./fixtures/smiley.png"),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
UI.clickTool("image");
|
||||||
|
|
||||||
|
await assert();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import { queryByTestId } from "@testing-library/react";
|
import { act, queryByTestId } from "@testing-library/react";
|
||||||
import { act } from "@testing-library/react";
|
import React from "react";
|
||||||
import { vi } from "vitest";
|
import { vi } from "vitest";
|
||||||
|
|
||||||
import { MIME_TYPES, ORIG_ID } from "@excalidraw/common";
|
import { MIME_TYPES, ORIG_ID } from "@excalidraw/common";
|
||||||
@ -13,11 +13,9 @@ import { serializeLibraryAsJSON } from "../data/json";
|
|||||||
import { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
import { distributeLibraryItemsOnSquareGrid } from "../data/library";
|
||||||
import { Excalidraw } from "../index";
|
import { Excalidraw } from "../index";
|
||||||
|
|
||||||
import { fireEvent, render, togglePopover, waitFor } from "./test-utils";
|
|
||||||
|
|
||||||
import { API } from "./helpers/api";
|
import { API } from "./helpers/api";
|
||||||
import { UI } from "./helpers/ui";
|
import { UI } from "./helpers/ui";
|
||||||
import { getCloneByOrigId } from "./test-utils";
|
import { fireEvent, getCloneByOrigId, render, waitFor } from "./test-utils";
|
||||||
|
|
||||||
import type { LibraryItem, LibraryItems } from "../types";
|
import type { LibraryItem, LibraryItems } from "../types";
|
||||||
|
|
||||||
@ -58,9 +56,13 @@ describe("library", () => {
|
|||||||
|
|
||||||
it("import library via drag&drop", async () => {
|
it("import library via drag&drop", async () => {
|
||||||
expect(await h.app.library.getLatestLibrary()).toEqual([]);
|
expect(await h.app.library.getLatestLibrary()).toEqual([]);
|
||||||
await API.drop(
|
await API.drop([
|
||||||
await API.loadFile("./fixtures/fixture_library.excalidrawlib"),
|
{
|
||||||
);
|
kind: "file",
|
||||||
|
type: MIME_TYPES.excalidrawlib,
|
||||||
|
file: await API.loadFile("./fixtures/fixture_library.excalidrawlib"),
|
||||||
|
},
|
||||||
|
]);
|
||||||
await waitFor(async () => {
|
await waitFor(async () => {
|
||||||
expect(await h.app.library.getLatestLibrary()).toEqual([
|
expect(await h.app.library.getLatestLibrary()).toEqual([
|
||||||
{
|
{
|
||||||
@ -77,11 +79,13 @@ describe("library", () => {
|
|||||||
it("drop library item onto canvas", async () => {
|
it("drop library item onto canvas", async () => {
|
||||||
expect(h.elements).toEqual([]);
|
expect(h.elements).toEqual([]);
|
||||||
const libraryItems = parseLibraryJSON(await libraryJSONPromise);
|
const libraryItems = parseLibraryJSON(await libraryJSONPromise);
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob([serializeLibraryAsJSON(libraryItems)], {
|
{
|
||||||
|
kind: "string",
|
||||||
|
value: serializeLibraryAsJSON(libraryItems),
|
||||||
type: MIME_TYPES.excalidrawlib,
|
type: MIME_TYPES.excalidrawlib,
|
||||||
}),
|
},
|
||||||
);
|
]);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([expect.objectContaining({ [ORIG_ID]: "A" })]);
|
expect(h.elements).toEqual([expect.objectContaining({ [ORIG_ID]: "A" })]);
|
||||||
});
|
});
|
||||||
@ -113,10 +117,10 @@ describe("library", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob(
|
{
|
||||||
[
|
kind: "string",
|
||||||
serializeLibraryAsJSON([
|
value: serializeLibraryAsJSON([
|
||||||
{
|
{
|
||||||
id: "item1",
|
id: "item1",
|
||||||
status: "published",
|
status: "published",
|
||||||
@ -124,12 +128,9 @@ describe("library", () => {
|
|||||||
created: 1,
|
created: 1,
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
],
|
|
||||||
{
|
|
||||||
type: MIME_TYPES.excalidrawlib,
|
type: MIME_TYPES.excalidrawlib,
|
||||||
},
|
},
|
||||||
),
|
]);
|
||||||
);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual(
|
expect(h.elements).toEqual(
|
||||||
@ -172,11 +173,13 @@ describe("library", () => {
|
|||||||
created: 1,
|
created: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob([serializeLibraryAsJSON([item1, item1])], {
|
{
|
||||||
|
kind: "string",
|
||||||
|
value: serializeLibraryAsJSON([item1, item1]),
|
||||||
type: MIME_TYPES.excalidrawlib,
|
type: MIME_TYPES.excalidrawlib,
|
||||||
}),
|
},
|
||||||
);
|
]);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([
|
expect(h.elements).toEqual([
|
||||||
@ -195,11 +198,13 @@ describe("library", () => {
|
|||||||
UI.clickTool("rectangle");
|
UI.clickTool("rectangle");
|
||||||
expect(h.elements).toEqual([]);
|
expect(h.elements).toEqual([]);
|
||||||
const libraryItems = parseLibraryJSON(await libraryJSONPromise);
|
const libraryItems = parseLibraryJSON(await libraryJSONPromise);
|
||||||
await API.drop(
|
await API.drop([
|
||||||
new Blob([serializeLibraryAsJSON(libraryItems)], {
|
{
|
||||||
|
kind: "string",
|
||||||
|
value: serializeLibraryAsJSON(libraryItems),
|
||||||
type: MIME_TYPES.excalidrawlib,
|
type: MIME_TYPES.excalidrawlib,
|
||||||
}),
|
},
|
||||||
);
|
]);
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(h.elements).toEqual([expect.objectContaining({ [ORIG_ID]: "A" })]);
|
expect(h.elements).toEqual([expect.objectContaining({ [ORIG_ID]: "A" })]);
|
||||||
});
|
});
|
||||||
@ -217,13 +222,12 @@ describe("library menu", () => {
|
|||||||
const libraryButton = container.querySelector(".sidebar-trigger");
|
const libraryButton = container.querySelector(".sidebar-trigger");
|
||||||
|
|
||||||
fireEvent.click(libraryButton!);
|
fireEvent.click(libraryButton!);
|
||||||
togglePopover("Library menu");
|
fireEvent.click(
|
||||||
// fireEvent.click(
|
queryByTestId(
|
||||||
// queryByTestId(
|
container.querySelector(".layer-ui__library")!,
|
||||||
// container.querySelector(".layer-ui__library")!,
|
"dropdown-menu-button",
|
||||||
// "dropdown-menu-button",
|
)!,
|
||||||
// )!,
|
);
|
||||||
// );
|
|
||||||
fireEvent.click(queryByTestId(container, "lib-dropdown--load")!);
|
fireEvent.click(queryByTestId(container, "lib-dropdown--load")!);
|
||||||
|
|
||||||
const libraryItems = parseLibraryJSON(await libraryJSONPromise);
|
const libraryItems = parseLibraryJSON(await libraryJSONPromise);
|
||||||
|
|||||||
@ -2,34 +2,15 @@
|
|||||||
|
|
||||||
exports[`<Excalidraw/> > <MainMenu/> > should render main menu with host menu items if passed from host 1`] = `
|
exports[`<Excalidraw/> > <MainMenu/> > should render main menu with host menu items if passed from host 1`] = `
|
||||||
<div
|
<div
|
||||||
aria-labelledby="radix-:r65:"
|
class="dropdown-menu"
|
||||||
aria-orientation="vertical"
|
|
||||||
class="dropdown-menu main-menu-content"
|
|
||||||
data-align="start"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-menu-content=""
|
|
||||||
data-side="bottom"
|
|
||||||
data-state="open"
|
|
||||||
data-testid="dropdown-menu"
|
data-testid="dropdown-menu"
|
||||||
dir="ltr"
|
|
||||||
id="radix-:r66:"
|
|
||||||
role="menu"
|
|
||||||
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); animation: none;"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="Island dropdown-menu-container"
|
class="Island dropdown-menu-container"
|
||||||
style="--padding: 1; z-index: 2;"
|
style="--padding: 2; z-index: 2;"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@ -41,7 +22,6 @@ exports[`<Excalidraw/> > <MainMenu/> > should render main menu with host menu it
|
|||||||
Click me
|
Click me
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<a
|
<a
|
||||||
class="dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
href="https://plus.excalidraw.com/blog"
|
href="https://plus.excalidraw.com/blog"
|
||||||
@ -66,16 +46,9 @@ exports[`<Excalidraw/> > <MainMenu/> > should render main menu with host menu it
|
|||||||
custom menu item
|
custom menu item
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-label="Help"
|
aria-label="Help"
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="help-menu-item"
|
data-testid="help-menu-item"
|
||||||
title="Help"
|
title="Help"
|
||||||
type="button"
|
type="button"
|
||||||
@ -133,40 +106,20 @@ exports[`<Excalidraw/> > <MainMenu/> > should render main menu with host menu it
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should render menu with default items when "UIOPtions" is "undefined" 1`] = `
|
exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should render menu with default items when "UIOPtions" is "undefined" 1`] = `
|
||||||
<div
|
<div
|
||||||
aria-labelledby="radix-:rq:"
|
class="dropdown-menu"
|
||||||
aria-orientation="vertical"
|
|
||||||
class="dropdown-menu main-menu-content"
|
|
||||||
data-align="start"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-menu-content=""
|
|
||||||
data-side="bottom"
|
|
||||||
data-state="open"
|
|
||||||
data-testid="dropdown-menu"
|
data-testid="dropdown-menu"
|
||||||
dir="ltr"
|
|
||||||
id="radix-:rr:"
|
|
||||||
role="menu"
|
|
||||||
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); animation: none;"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="Island dropdown-menu-container"
|
class="Island dropdown-menu-container"
|
||||||
style="--padding: 1; z-index: 2;"
|
style="--padding: 2; z-index: 2;"
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
aria-label="Open"
|
aria-label="Open"
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="load-button"
|
data-testid="load-button"
|
||||||
title="Open"
|
title="Open"
|
||||||
type="button"
|
type="button"
|
||||||
@ -202,17 +155,9 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
Ctrl+O
|
Ctrl+O
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-label="Save to..."
|
aria-label="Save to..."
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="json-export-button"
|
data-testid="json-export-button"
|
||||||
title="Save to..."
|
title="Save to..."
|
||||||
type="button"
|
type="button"
|
||||||
@ -243,17 +188,9 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
Save to...
|
Save to...
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-label="Export image..."
|
aria-label="Export image..."
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="image-export-button"
|
data-testid="image-export-button"
|
||||||
title="Export image..."
|
title="Export image..."
|
||||||
type="button"
|
type="button"
|
||||||
@ -313,17 +250,9 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
Ctrl+Shift+E
|
Ctrl+Shift+E
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-label="Help"
|
aria-label="Help"
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="help-menu-item"
|
data-testid="help-menu-item"
|
||||||
title="Help"
|
title="Help"
|
||||||
type="button"
|
type="button"
|
||||||
@ -379,17 +308,9 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
?
|
?
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-label="Reset the canvas"
|
aria-label="Reset the canvas"
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="clear-canvas-button"
|
data-testid="clear-canvas-button"
|
||||||
title="Reset the canvas"
|
title="Reset the canvas"
|
||||||
type="button"
|
type="button"
|
||||||
@ -420,7 +341,6 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
Reset the canvas
|
Reset the canvas
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
style="height: 1px; margin: .5rem 0px;"
|
style="height: 1px; margin: .5rem 0px;"
|
||||||
/>
|
/>
|
||||||
@ -553,16 +473,9 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
<div
|
<div
|
||||||
style="height: 1px; margin: .5rem 0px;"
|
style="height: 1px; margin: .5rem 0px;"
|
||||||
/>
|
/>
|
||||||
<div
|
|
||||||
class="radix-menu-item"
|
|
||||||
data-orientation="vertical"
|
|
||||||
data-radix-collection-item=""
|
|
||||||
role="menuitem"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<button
|
<button
|
||||||
aria-label="Dark mode"
|
aria-label="Dark mode"
|
||||||
class="excalidraw-button dropdown-menu-item dropdown-menu-item-base"
|
class="dropdown-menu-item dropdown-menu-item-base"
|
||||||
data-testid="toggle-dark-mode"
|
data-testid="toggle-dark-mode"
|
||||||
title="Dark mode"
|
title="Dark mode"
|
||||||
type="button"
|
type="button"
|
||||||
@ -599,7 +512,6 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
Shift+Alt+D
|
Shift+Alt+D
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
style="margin-top: 0.5rem;"
|
style="margin-top: 0.5rem;"
|
||||||
>
|
>
|
||||||
@ -610,7 +522,6 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
Canvas background
|
Canvas background
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
id="canvas-bg-color-picker-container"
|
|
||||||
style="padding: 0px 0.625rem;"
|
style="padding: 0px 0.625rem;"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
@ -682,7 +593,7 @@ exports[`<Excalidraw/> > Test UIOptions prop > Test canvasActions > should rende
|
|||||||
style="width: 1px; height: 100%; margin: 0px auto;"
|
style="width: 1px; height: 100%; margin: 0px auto;"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
aria-controls="radix-:r12:"
|
aria-controls="radix-:r0:"
|
||||||
aria-expanded="false"
|
aria-expanded="false"
|
||||||
aria-haspopup="dialog"
|
aria-haspopup="dialog"
|
||||||
aria-label="Canvas background"
|
aria-label="Canvas background"
|
||||||
|
|||||||
@ -352,6 +352,10 @@ export interface AppState {
|
|||||||
| "elementBackground"
|
| "elementBackground"
|
||||||
| "elementStroke"
|
| "elementStroke"
|
||||||
| "fontFamily"
|
| "fontFamily"
|
||||||
|
| "compactTextProperties"
|
||||||
|
| "compactStrokeStyles"
|
||||||
|
| "compactOtherProperties"
|
||||||
|
| "compactArrowProperties"
|
||||||
| null;
|
| null;
|
||||||
openSidebar: { name: SidebarName; tab?: SidebarTabName } | null;
|
openSidebar: { name: SidebarName; tab?: SidebarTabName } | null;
|
||||||
openDialog:
|
openDialog:
|
||||||
@ -442,6 +446,9 @@ export interface AppState {
|
|||||||
// as elements are unlocked, we remove the groupId from the elements
|
// as elements are unlocked, we remove the groupId from the elements
|
||||||
// and also remove groupId from this map
|
// and also remove groupId from this map
|
||||||
lockedMultiSelections: { [groupId: string]: true };
|
lockedMultiSelections: { [groupId: string]: true };
|
||||||
|
|
||||||
|
/** properties sidebar mode - determines whether to show compact or complete sidebar */
|
||||||
|
stylesPanelMode: "compact" | "full";
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SearchMatch = {
|
export type SearchMatch = {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import {
|
|||||||
getFontString,
|
getFontString,
|
||||||
getFontFamilyString,
|
getFontFamilyString,
|
||||||
isTestEnv,
|
isTestEnv,
|
||||||
|
MIME_TYPES,
|
||||||
} from "@excalidraw/common";
|
} from "@excalidraw/common";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -45,7 +46,7 @@ import type {
|
|||||||
|
|
||||||
import { actionSaveToActiveFile } from "../actions";
|
import { actionSaveToActiveFile } from "../actions";
|
||||||
|
|
||||||
import { parseClipboard } from "../clipboard";
|
import { parseDataTransferEvent } from "../clipboard";
|
||||||
import {
|
import {
|
||||||
actionDecreaseFontSize,
|
actionDecreaseFontSize,
|
||||||
actionIncreaseFontSize,
|
actionIncreaseFontSize,
|
||||||
@ -332,12 +333,14 @@ export const textWysiwyg = ({
|
|||||||
|
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
editable.onpaste = async (event) => {
|
editable.onpaste = async (event) => {
|
||||||
const clipboardData = await parseClipboard(event, true);
|
const textItem = (await parseDataTransferEvent(event)).findByType(
|
||||||
if (!clipboardData.text) {
|
MIME_TYPES.text,
|
||||||
|
);
|
||||||
|
if (!textItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = normalizeText(clipboardData.text);
|
const text = normalizeText(textItem.value);
|
||||||
if (!data) {
|
if (!text) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const container = getContainerElement(
|
const container = getContainerElement(
|
||||||
@ -355,7 +358,7 @@ export const textWysiwyg = ({
|
|||||||
app.scene.getNonDeletedElementsMap(),
|
app.scene.getNonDeletedElementsMap(),
|
||||||
);
|
);
|
||||||
const wrappedText = wrapText(
|
const wrappedText = wrapText(
|
||||||
`${editable.value}${data}`,
|
`${editable.value}${text}`,
|
||||||
font,
|
font,
|
||||||
getBoundTextMaxWidth(container, boundTextElement),
|
getBoundTextMaxWidth(container, boundTextElement),
|
||||||
);
|
);
|
||||||
@ -539,6 +542,7 @@ export const textWysiwyg = ({
|
|||||||
if (isDestroyed) {
|
if (isDestroyed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDestroyed = true;
|
isDestroyed = true;
|
||||||
// cleanup must be run before onSubmit otherwise when app blurs the wysiwyg
|
// cleanup must be run before onSubmit otherwise when app blurs the wysiwyg
|
||||||
// it'd get stuck in an infinite loop of blur→onSubmit after we re-focus the
|
// it'd get stuck in an infinite loop of blur→onSubmit after we re-focus the
|
||||||
@ -622,14 +626,24 @@ export const textWysiwyg = ({
|
|||||||
const isPropertiesTrigger =
|
const isPropertiesTrigger =
|
||||||
target instanceof HTMLElement &&
|
target instanceof HTMLElement &&
|
||||||
target.classList.contains("properties-trigger");
|
target.classList.contains("properties-trigger");
|
||||||
|
const isPropertiesContent =
|
||||||
|
(target instanceof HTMLElement || target instanceof SVGElement) &&
|
||||||
|
!!(target as Element).closest(".properties-content");
|
||||||
|
const inShapeActionsMenu =
|
||||||
|
(target instanceof HTMLElement || target instanceof SVGElement) &&
|
||||||
|
(!!(target as Element).closest(`.${CLASSES.SHAPE_ACTIONS_MENU}`) ||
|
||||||
|
!!(target as Element).closest(".compact-shape-actions-island"));
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
editable.onblur = handleSubmit;
|
// If we interacted within shape actions menu or its popovers/triggers,
|
||||||
|
// keep submit disabled and don't steal focus back to textarea.
|
||||||
// case: clicking on the same property → no change → no update → no focus
|
if (inShapeActionsMenu || isPropertiesTrigger || isPropertiesContent) {
|
||||||
if (!isPropertiesTrigger) {
|
return;
|
||||||
editable.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, re-enable submit on blur and refocus the editor.
|
||||||
|
editable.onblur = handleSubmit;
|
||||||
|
editable.focus();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -652,6 +666,7 @@ export const textWysiwyg = ({
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
app.handleCanvasPanUsingWheelOrSpaceDrag(event);
|
app.handleCanvasPanUsingWheelOrSpaceDrag(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
temporarilyDisableSubmit();
|
temporarilyDisableSubmit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -659,15 +674,20 @@ export const textWysiwyg = ({
|
|||||||
const isPropertiesTrigger =
|
const isPropertiesTrigger =
|
||||||
target instanceof HTMLElement &&
|
target instanceof HTMLElement &&
|
||||||
target.classList.contains("properties-trigger");
|
target.classList.contains("properties-trigger");
|
||||||
|
const isPropertiesContent =
|
||||||
|
(target instanceof HTMLElement || target instanceof SVGElement) &&
|
||||||
|
!!(target as Element).closest(".properties-content");
|
||||||
|
|
||||||
if (
|
if (
|
||||||
((event.target instanceof HTMLElement ||
|
((event.target instanceof HTMLElement ||
|
||||||
event.target instanceof SVGElement) &&
|
event.target instanceof SVGElement) &&
|
||||||
event.target.closest(
|
(event.target.closest(
|
||||||
`.${CLASSES.SHAPE_ACTIONS_MENU}, .${CLASSES.ZOOM_ACTIONS}`,
|
`.${CLASSES.SHAPE_ACTIONS_MENU}, .${CLASSES.ZOOM_ACTIONS}`,
|
||||||
) &&
|
) ||
|
||||||
|
event.target.closest(".compact-shape-actions-island")) &&
|
||||||
!isWritableElement(event.target)) ||
|
!isWritableElement(event.target)) ||
|
||||||
isPropertiesTrigger
|
isPropertiesTrigger ||
|
||||||
|
isPropertiesContent
|
||||||
) {
|
) {
|
||||||
temporarilyDisableSubmit();
|
temporarilyDisableSubmit();
|
||||||
} else if (
|
} else if (
|
||||||
|
|||||||
@ -177,3 +177,19 @@ export function lineSegmentIntersectionPoints<
|
|||||||
|
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function lineSegmentsDistance<Point extends GlobalPoint | LocalPoint>(
|
||||||
|
s1: LineSegment<Point>,
|
||||||
|
s2: LineSegment<Point>,
|
||||||
|
): number {
|
||||||
|
if (lineSegmentIntersectionPoints(s1, s2)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.min(
|
||||||
|
distanceToLineSegment(s1[0], s2),
|
||||||
|
distanceToLineSegment(s1[1], s2),
|
||||||
|
distanceToLineSegment(s2[0], s1),
|
||||||
|
distanceToLineSegment(s2[1], s1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@ -100,6 +100,7 @@ exports[`exportToSvg > with default arguments 1`] = `
|
|||||||
"open": false,
|
"open": false,
|
||||||
"panels": 3,
|
"panels": 3,
|
||||||
},
|
},
|
||||||
|
"stylesPanelMode": "full",
|
||||||
"suggestedBindings": [],
|
"suggestedBindings": [],
|
||||||
"theme": "light",
|
"theme": "light",
|
||||||
"toast": null,
|
"toast": null,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user