Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ed78d4895 | |||
| 5ba2798306 | |||
| b8aae34e32 | |||
| 6317ac16ee | |||
| 9ad75b8375 | |||
| 4c9ad1a22f | |||
| 023895b49b | |||
| eb37be953a |
@@ -0,0 +1,27 @@
|
||||
name: Playwright Tests
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master ]
|
||||
pull_request:
|
||||
branches: [ main, master ]
|
||||
jobs:
|
||||
test:
|
||||
timeout-minutes: 60
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: lts/*
|
||||
- name: Install dependencies
|
||||
run: npm install -g yarn && yarn
|
||||
- name: Install Playwright Browsers
|
||||
run: yarn playwright install --with-deps
|
||||
- name: Run Playwright tests
|
||||
run: yarn playwright test
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: ${{ !cancelled() }}
|
||||
with:
|
||||
name: playwright-report
|
||||
path: playwright-report/
|
||||
retention-days: 30
|
||||
@@ -27,3 +27,9 @@ dev-dist
|
||||
html
|
||||
meta*.json
|
||||
.claude
|
||||
|
||||
# Playwright
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
excalidraw:
|
||||
build:
|
||||
|
||||
+9
-10
@@ -20,6 +20,7 @@ import {
|
||||
APP_NAME,
|
||||
EVENT,
|
||||
THEME,
|
||||
TITLE_TIMEOUT,
|
||||
VERSION_TIMEOUT,
|
||||
debounce,
|
||||
getVersion,
|
||||
@@ -73,6 +74,7 @@ import type {
|
||||
import type { ResolutionType } from "@excalidraw/common/utility-types";
|
||||
import type { ResolvablePromise } from "@excalidraw/common/utils";
|
||||
|
||||
import "./record";
|
||||
import CustomStats from "./CustomStats";
|
||||
import {
|
||||
Provider,
|
||||
@@ -119,7 +121,6 @@ import {
|
||||
LibraryIndexedDBAdapter,
|
||||
LibraryLocalStorageMigrationAdapter,
|
||||
LocalData,
|
||||
localStorageQuotaExceededAtom,
|
||||
} from "./data/LocalData";
|
||||
import { isBrowserStorageStateNewer } from "./data/tabSync";
|
||||
import { ShareDialog, shareDialogStateAtom } from "./share/ShareDialog";
|
||||
@@ -499,6 +500,11 @@ const ExcalidrawWrapper = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const titleTimeout = setTimeout(
|
||||
() => (document.title = APP_NAME),
|
||||
TITLE_TIMEOUT,
|
||||
);
|
||||
|
||||
const syncData = debounce(() => {
|
||||
if (isTestEnv()) {
|
||||
return;
|
||||
@@ -589,6 +595,7 @@ const ExcalidrawWrapper = () => {
|
||||
visibilityChange,
|
||||
false,
|
||||
);
|
||||
clearTimeout(titleTimeout);
|
||||
};
|
||||
}, [isCollabDisabled, collabAPI, excalidrawAPI, setLangCode]);
|
||||
|
||||
@@ -728,8 +735,6 @@ const ExcalidrawWrapper = () => {
|
||||
|
||||
const isOffline = useAtomValue(isOfflineAtom);
|
||||
|
||||
const localStorageQuotaExceeded = useAtomValue(localStorageQuotaExceededAtom);
|
||||
|
||||
const onCollabDialogOpen = useCallback(
|
||||
() => setShareDialogState({ isOpen: true, type: "collaborationOnly" }),
|
||||
[setShareDialogState],
|
||||
@@ -904,15 +909,10 @@ const ExcalidrawWrapper = () => {
|
||||
|
||||
<TTDDialogTrigger />
|
||||
{isCollaborating && isOffline && (
|
||||
<div className="alertalert--warning">
|
||||
<div className="collab-offline-warning">
|
||||
{t("alerts.collabOfflineWarning")}
|
||||
</div>
|
||||
)}
|
||||
{localStorageQuotaExceeded && (
|
||||
<div className="alert alert--danger">
|
||||
{t("alerts.localStorageQuotaExceeded")}
|
||||
</div>
|
||||
)}
|
||||
{latestShareableLink && (
|
||||
<ShareableLinkDialog
|
||||
link={latestShareableLink}
|
||||
@@ -1143,7 +1143,6 @@ const ExcalidrawWrapper = () => {
|
||||
ref={debugCanvasRef}
|
||||
/>
|
||||
)}
|
||||
{/* <FreedrawDebugSliders /> */}
|
||||
</Excalidraw>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -8,8 +8,7 @@ export const SYNC_BROWSER_TABS_TIMEOUT = 50;
|
||||
export const CURSOR_SYNC_TIMEOUT = 33; // ~30fps
|
||||
export const DELETED_ELEMENT_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
|
||||
|
||||
// should be aligned with MAX_ALLOWED_FILE_BYTES
|
||||
export const FILE_UPLOAD_MAX_BYTES = 4 * 1024 * 1024; // 4 MiB
|
||||
export const FILE_UPLOAD_MAX_BYTES = 3 * 1024 * 1024; // 3 MiB
|
||||
// 1 year (https://stackoverflow.com/a/25201898/927631)
|
||||
export const FILE_CACHE_MAX_AGE_SEC = 31536000;
|
||||
|
||||
|
||||
@@ -530,10 +530,7 @@ class Collab extends PureComponent<CollabProps, CollabState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (existingRoomLinkData) {
|
||||
// when joining existing room, don't merge it with current scene data
|
||||
this.excalidrawAPI.resetScene();
|
||||
} else {
|
||||
if (!existingRoomLinkData) {
|
||||
const elements = this.excalidrawAPI.getSceneElements().map((element) => {
|
||||
if (isImageElement(element) && element.status === "saved") {
|
||||
return newElementWith(element, { status: "pending" });
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
import { STROKE_OPTIONS, isFreeDrawElement } from "@excalidraw/element";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import { useUIAppState } from "@excalidraw/excalidraw/context/ui-appState";
|
||||
import { useExcalidrawElements } from "@excalidraw/excalidraw/components/App";
|
||||
|
||||
import { round } from "../../packages/math/src";
|
||||
|
||||
export const FreedrawDebugSliders = () => {
|
||||
const [streamline, setStreamline] = useState<number>(
|
||||
STROKE_OPTIONS.default.streamline,
|
||||
);
|
||||
const [simplify, setSimplify] = useState<number>(
|
||||
STROKE_OPTIONS.default.simplify,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!window.h) {
|
||||
window.h = {} as any;
|
||||
}
|
||||
if (!window.h.debugFreedraw) {
|
||||
window.h.debugFreedraw = {
|
||||
enabled: true,
|
||||
...STROKE_OPTIONS.default,
|
||||
};
|
||||
}
|
||||
|
||||
setStreamline(window.h.debugFreedraw.streamline);
|
||||
setSimplify(window.h.debugFreedraw.simplify);
|
||||
}, []);
|
||||
|
||||
const handleStreamlineChange = (value: number) => {
|
||||
setStreamline(value);
|
||||
if (window.h && window.h.debugFreedraw) {
|
||||
window.h.debugFreedraw.streamline = value;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSimplifyChange = (value: number) => {
|
||||
setSimplify(value);
|
||||
if (window.h && window.h.debugFreedraw) {
|
||||
window.h.debugFreedraw.simplify = value;
|
||||
}
|
||||
};
|
||||
|
||||
const [enabled, setEnabled] = useState<boolean>(
|
||||
window.h?.debugFreedraw?.enabled ?? true,
|
||||
);
|
||||
|
||||
// counter incrasing each 50ms
|
||||
const [, setCounter] = useState<number>(0);
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setCounter((prev) => prev + 1);
|
||||
}, 50);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const elements = useExcalidrawElements();
|
||||
const appState = useUIAppState();
|
||||
|
||||
const newFreedrawElement =
|
||||
appState.newElement && isFreeDrawElement(appState.newElement)
|
||||
? appState.newElement
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
bottom: "70px",
|
||||
left: "50%",
|
||||
transform: "translateX(-50%)",
|
||||
zIndex: 9999,
|
||||
padding: "10px",
|
||||
borderRadius: "8px",
|
||||
border: "1px solid #ccc",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "8px",
|
||||
fontSize: "12px",
|
||||
fontFamily: "monospace",
|
||||
}}
|
||||
>
|
||||
{newFreedrawElement && (
|
||||
<div>
|
||||
pressures:{" "}
|
||||
{newFreedrawElement.simulatePressure
|
||||
? "simulated"
|
||||
: JSON.stringify(
|
||||
newFreedrawElement.pressures
|
||||
.slice(-4)
|
||||
.map((x) => round(x, 2))
|
||||
.join(" ") || [],
|
||||
)}{" "}
|
||||
({round(window.__lastPressure__ || 0, 2) || "?"})
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<label>
|
||||
{" "}
|
||||
enabled
|
||||
<br />
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={enabled}
|
||||
onChange={(e) => {
|
||||
if (window.h.debugFreedraw) {
|
||||
window.h.debugFreedraw.enabled = e.target.checked;
|
||||
setEnabled(e.target.checked);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
Streamline: {streamline.toFixed(2)}
|
||||
<br />
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
value={streamline}
|
||||
onChange={(e) => handleStreamlineChange(parseFloat(e.target.value))}
|
||||
style={{ width: "150px" }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>
|
||||
Simplify: {simplify.toFixed(2)}
|
||||
<br />
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.01"
|
||||
value={simplify}
|
||||
onChange={(e) => handleSimplifyChange(parseFloat(e.target.value))}
|
||||
style={{ width: "150px" }}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -27,8 +27,6 @@ import {
|
||||
get,
|
||||
} from "idb-keyval";
|
||||
|
||||
import { appJotaiStore, atom } from "excalidraw-app/app-jotai";
|
||||
|
||||
import type { LibraryPersistedData } from "@excalidraw/excalidraw/data/library";
|
||||
import type { ImportedDataState } from "@excalidraw/excalidraw/data/types";
|
||||
import type { ExcalidrawElement, FileId } from "@excalidraw/element/types";
|
||||
@@ -47,8 +45,6 @@ import { updateBrowserStateVersion } from "./tabSync";
|
||||
|
||||
const filesStore = createStore("files-db", "files-store");
|
||||
|
||||
export const localStorageQuotaExceededAtom = atom(false);
|
||||
|
||||
class LocalFileManager extends FileManager {
|
||||
clearObsoleteFiles = async (opts: { currentFileIds: FileId[] }) => {
|
||||
await entries(filesStore).then((entries) => {
|
||||
@@ -73,9 +69,6 @@ const saveDataStateToLocalStorage = (
|
||||
elements: readonly ExcalidrawElement[],
|
||||
appState: AppState,
|
||||
) => {
|
||||
const localStorageQuotaExceeded = appJotaiStore.get(
|
||||
localStorageQuotaExceededAtom,
|
||||
);
|
||||
try {
|
||||
const _appState = clearAppStateForLocalStorage(appState);
|
||||
|
||||
@@ -95,22 +88,12 @@ const saveDataStateToLocalStorage = (
|
||||
JSON.stringify(_appState),
|
||||
);
|
||||
updateBrowserStateVersion(STORAGE_KEYS.VERSION_DATA_STATE);
|
||||
if (localStorageQuotaExceeded) {
|
||||
appJotaiStore.set(localStorageQuotaExceededAtom, false);
|
||||
}
|
||||
} catch (error: any) {
|
||||
// Unable to access window.localStorage
|
||||
console.error(error);
|
||||
if (isQuotaExceededError(error) && !localStorageQuotaExceeded) {
|
||||
appJotaiStore.set(localStorageQuotaExceededAtom, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isQuotaExceededError = (error: any) => {
|
||||
return error instanceof DOMException && error.name === "QuotaExceededError";
|
||||
};
|
||||
|
||||
type SavingLockTypes = "collaboration";
|
||||
|
||||
export class LocalData {
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Excalidraw Whiteboard</title>
|
||||
<title>
|
||||
Free, collaborative whiteboard • Hand-drawn look & feel | Excalidraw
|
||||
</title>
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover, shrink-to-fit=no"
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.alert {
|
||||
.collab-offline-warning {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 6.5rem;
|
||||
@@ -69,18 +69,10 @@
|
||||
text-align: center;
|
||||
line-height: 1.5;
|
||||
border-radius: var(--border-radius-md);
|
||||
background-color: var(--color-warning);
|
||||
color: var(--color-text-warning);
|
||||
z-index: 6;
|
||||
white-space: pre;
|
||||
|
||||
&--warning {
|
||||
background-color: var(--color-warning);
|
||||
color: var(--color-text-warning);
|
||||
}
|
||||
|
||||
&--danger {
|
||||
background-color: var(--color-danger-dark);
|
||||
color: var(--color-danger-text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"build:version": "node ../scripts/build-version.js",
|
||||
"build": "yarn build:app && yarn build:version",
|
||||
"start": "yarn && vite",
|
||||
"start:test": "yarn && vite --mode test",
|
||||
"start:production": "yarn build && yarn serve",
|
||||
"serve": "npx http-server build -a localhost -p 5001 -o",
|
||||
"build:preview": "yarn build && vite preview --port 5000"
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
import { isDevEnv } from "@excalidraw/common";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
record: typeof Record;
|
||||
}
|
||||
}
|
||||
|
||||
export class Record {
|
||||
private static recording: boolean = false;
|
||||
private static events: string = "";
|
||||
private static timestamp: number = 0;
|
||||
|
||||
public static get isRecording() {
|
||||
return Record.recording;
|
||||
}
|
||||
|
||||
private static header() {
|
||||
Record.events += " await page.addInitScript(() => {\n";
|
||||
Record.events += " Math.random = () => 0.42;\n\n";
|
||||
|
||||
// Capture LocalStorage, which is essential to re-establish state
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key != null) {
|
||||
const value = JSON.stringify(localStorage.getItem(key));
|
||||
Record.events += ` localStorage.getItem("${key}");\n`;
|
||||
Record.events += ` localStorage.setItem("${key}", ${value});\n`;
|
||||
}
|
||||
}
|
||||
Record.events += " });\n";
|
||||
Record.events += ` await page.setViewportSize({ width: ${window.innerWidth}, height: ${window.innerHeight} });\n`;
|
||||
Record.events += ` await page.goto("http://localhost:3000");\n`;
|
||||
Record.events += ` await page.waitForLoadState("load");\n`;
|
||||
}
|
||||
|
||||
public static restart() {
|
||||
if (!Record.recording) {
|
||||
Record.start();
|
||||
return;
|
||||
}
|
||||
|
||||
Record.events += `});\n\n`;
|
||||
Record.events += `test("${
|
||||
Date.now() + Math.floor(Math.random() * Date.now()).toString(36)
|
||||
}", async ({ page }) => {\n`;
|
||||
|
||||
Record.header();
|
||||
}
|
||||
|
||||
public static start() {
|
||||
Record.recording = true;
|
||||
|
||||
// Record header
|
||||
this.header();
|
||||
|
||||
// Set up the events
|
||||
Record.timestamp = performance.now();
|
||||
|
||||
window.addEventListener("mousemove", this.onMouseMove);
|
||||
window.addEventListener("mousedown", this.onMouseDown);
|
||||
window.addEventListener("mouseup", this.onMouseUp);
|
||||
window.addEventListener("keydown", this.onKeyDown);
|
||||
window.addEventListener("keyup", this.onKeyUp);
|
||||
}
|
||||
|
||||
public static stop() {
|
||||
window.removeEventListener("mousemove", this.onMouseMove);
|
||||
window.removeEventListener("mousedown", this.onMouseDown);
|
||||
window.removeEventListener("mouseup", this.onMouseUp);
|
||||
window.removeEventListener("keydown", this.onKeyDown);
|
||||
window.removeEventListener("keyup", this.onKeyUp);
|
||||
Record.recording = false;
|
||||
}
|
||||
|
||||
/// Displays a window as an absolutely positioned DIV with the generated
|
||||
/// events within <pre> tags as formatted JSON, so it can be copied easily.
|
||||
public static showGeneratedEvents() {
|
||||
if (Record.recording) {
|
||||
Record.stop();
|
||||
}
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.style.position = "absolute";
|
||||
div.style.top = "10px";
|
||||
div.style.right = "10px";
|
||||
div.style.left = "10px";
|
||||
div.style.height = "60vh";
|
||||
div.style.backgroundColor = "gray";
|
||||
div.style.padding = "10px";
|
||||
div.style.zIndex = "10000";
|
||||
|
||||
const pre = document.createElement("pre");
|
||||
|
||||
let textContent = `import { expect, test } from "@playwright/test";\n\n`;
|
||||
textContent += `test("${
|
||||
Date.now() + Math.floor(Math.random() * Date.now()).toString(36)
|
||||
}", async ({ page }) => {\n`;
|
||||
textContent += Record.events;
|
||||
textContent += `});\n`;
|
||||
|
||||
pre.textContent = textContent;
|
||||
//pre.textContent = Record.events;
|
||||
|
||||
pre.style.marginTop = "18px";
|
||||
pre.style.maxHeight = "60vh";
|
||||
pre.style.overflow = "auto";
|
||||
div.appendChild(pre);
|
||||
|
||||
const copyBtn = document.createElement("button");
|
||||
copyBtn.textContent = "Copy";
|
||||
copyBtn.title = "Copy generated events to clipboard";
|
||||
copyBtn.setAttribute("aria-label", "Copy generated events to clipboard");
|
||||
copyBtn.style.position = "absolute";
|
||||
copyBtn.style.top = "4px";
|
||||
copyBtn.style.left = "4px";
|
||||
copyBtn.style.border = "none";
|
||||
copyBtn.style.background = "transparent";
|
||||
copyBtn.style.fontSize = "12px";
|
||||
copyBtn.style.lineHeight = "1";
|
||||
copyBtn.style.cursor = "pointer";
|
||||
copyBtn.style.padding = "4px 8px";
|
||||
copyBtn.addEventListener("click", async () => {
|
||||
const text = pre.textContent ?? "";
|
||||
try {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
const ta = document.createElement("textarea");
|
||||
ta.value = text;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(ta);
|
||||
}
|
||||
const orig = copyBtn.textContent;
|
||||
copyBtn.textContent = "Copied";
|
||||
setTimeout(() => (copyBtn.textContent = orig), 1000);
|
||||
} catch {}
|
||||
});
|
||||
div.appendChild(copyBtn);
|
||||
|
||||
const closeBtn = document.createElement("button");
|
||||
closeBtn.textContent = "×";
|
||||
closeBtn.title = "Close";
|
||||
closeBtn.style.position = "absolute";
|
||||
closeBtn.style.top = "4px";
|
||||
closeBtn.style.right = "4px";
|
||||
closeBtn.style.border = "none";
|
||||
closeBtn.style.background = "transparent";
|
||||
closeBtn.style.fontSize = "18px";
|
||||
closeBtn.style.lineHeight = "1";
|
||||
closeBtn.style.cursor = "pointer";
|
||||
closeBtn.addEventListener("click", () => {
|
||||
// remove the dialog from DOM
|
||||
if (div.parentNode) {
|
||||
div.parentNode.removeChild(div);
|
||||
}
|
||||
});
|
||||
div.appendChild(closeBtn);
|
||||
|
||||
document.body.appendChild(div);
|
||||
}
|
||||
|
||||
private static onMouseMove(event: MouseEvent) {
|
||||
if (
|
||||
event.clientX < 0 ||
|
||||
event.clientX > window.innerWidth ||
|
||||
event.clientY < 0 ||
|
||||
event.clientY > window.innerHeight
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const now = event.timeStamp || performance.now();
|
||||
const delay = now - Record.timestamp;
|
||||
Record.timestamp = now;
|
||||
|
||||
if (delay > 0) {
|
||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
||||
}
|
||||
Record.events += ` await page.mouse.move(${event.clientX}, ${event.clientY});\n`;
|
||||
}
|
||||
|
||||
private static onMouseDown(event: MouseEvent) {
|
||||
const now = event.timeStamp || performance.now();
|
||||
const delay = now - Record.timestamp;
|
||||
Record.timestamp = now;
|
||||
|
||||
if (delay > 0) {
|
||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
||||
}
|
||||
const button =
|
||||
event.button === 0 ? "left" : event.button === 1 ? "middle" : "right";
|
||||
Record.events += ` await page.mouse.down({ button: "${button}" });\n`;
|
||||
}
|
||||
|
||||
private static onMouseUp(event: MouseEvent) {
|
||||
const now = event.timeStamp || performance.now();
|
||||
const delay = now - Record.timestamp;
|
||||
Record.timestamp = now;
|
||||
|
||||
if (delay > 0) {
|
||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
||||
}
|
||||
const button =
|
||||
event.button === 0 ? "left" : event.button === 1 ? "middle" : "right";
|
||||
Record.events += ` await page.mouse.up({ button: "${button}" });\n`;
|
||||
|
||||
Record.events += " await expect(page).toHaveScreenshot({\n";
|
||||
Record.events += " maxDiffPixels: 100,\n";
|
||||
Record.events += " maxDiffPixelRatio: 0.01,\n";
|
||||
Record.events += " });\n";
|
||||
}
|
||||
|
||||
private static onKeyDown(event: KeyboardEvent) {
|
||||
// Only record if the recording key is not pressed
|
||||
if (event.key !== "F2") {
|
||||
const now = event.timeStamp || performance.now();
|
||||
const delay = now - Record.timestamp;
|
||||
Record.timestamp = now;
|
||||
|
||||
if (delay > 0) {
|
||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
||||
}
|
||||
Record.events += ` await page.keyboard.down("${event.key}");\n`;
|
||||
}
|
||||
}
|
||||
|
||||
private static onKeyUp(event: KeyboardEvent) {
|
||||
// Only record if the recording key is not pressed
|
||||
if (event.key !== "F2") {
|
||||
const now = event.timeStamp || performance.now();
|
||||
const delay = now - Record.timestamp;
|
||||
Record.timestamp = now;
|
||||
|
||||
if (delay > 0) {
|
||||
Record.events += ` await page.waitForTimeout(${delay});\n`;
|
||||
}
|
||||
Record.events += ` await page.keyboard.up("${event.key}");\n`;
|
||||
|
||||
Record.events += " await expect(page).toHaveScreenshot({\n";
|
||||
Record.events += " maxDiffPixels: 100,\n";
|
||||
Record.events += " maxDiffPixelRatio: 0.01,\n";
|
||||
Record.events += " });\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isDevEnv()) {
|
||||
window.record = Record;
|
||||
|
||||
window.addEventListener("keyup", (event) => {
|
||||
if (event.key === "F2") {
|
||||
if (Record.isRecording) {
|
||||
if (event.ctrlKey) {
|
||||
console.info("Stopping Playwright recording");
|
||||
Record.stop();
|
||||
} else {
|
||||
Record.restart();
|
||||
}
|
||||
} else {
|
||||
console.info("Starting Playwright recording");
|
||||
Record.start();
|
||||
}
|
||||
} else if (event.key === "Enter" && event.ctrlKey) {
|
||||
Record.showGeneratedEvents();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { defaultLang } from "@excalidraw/excalidraw/i18n";
|
||||
import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
|
||||
import {
|
||||
screen,
|
||||
fireEvent,
|
||||
waitFor,
|
||||
render,
|
||||
} from "@excalidraw/excalidraw/tests/test-utils";
|
||||
|
||||
import ExcalidrawApp from "../App";
|
||||
|
||||
describe("Test LanguageList", () => {
|
||||
it("rerenders UI on language change", async () => {
|
||||
await render(<ExcalidrawApp />);
|
||||
|
||||
// select rectangle tool to show properties menu
|
||||
UI.clickTool("rectangle");
|
||||
// english lang should display `thin` label
|
||||
expect(screen.queryByTitle(/thin/i)).not.toBeNull();
|
||||
fireEvent.click(document.querySelector(".dropdown-menu-button")!);
|
||||
|
||||
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
|
||||
target: { value: "de-DE" },
|
||||
});
|
||||
// switching to german, `thin` label should no longer exist
|
||||
await waitFor(() => expect(screen.queryByTitle(/thin/i)).toBeNull());
|
||||
// reset language
|
||||
fireEvent.change(document.querySelector(".dropdown-select__language")!, {
|
||||
target: { value: defaultLang.code },
|
||||
});
|
||||
// switching back to English
|
||||
await waitFor(() => expect(screen.queryByTitle(/thin/i)).not.toBeNull());
|
||||
});
|
||||
});
|
||||
@@ -36,7 +36,7 @@ describe("Test MobileMenu", () => {
|
||||
},
|
||||
"isTouchScreen": false,
|
||||
"viewport": {
|
||||
"isLandscape": true,
|
||||
"isLandscape": false,
|
||||
"isMobile": true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -0,0 +1,716 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test("17562123239901g67cqde", async ({ page }) => {
|
||||
await page.addInitScript(() => {
|
||||
Math.random = () => 0.42;
|
||||
|
||||
localStorage.getItem("i18nextLng");
|
||||
localStorage.setItem("i18nextLng", "en");
|
||||
localStorage.getItem("excalidraw-collab");
|
||||
localStorage.setItem("excalidraw-collab", '{"username":""}');
|
||||
localStorage.getItem("excalidraw-debug");
|
||||
localStorage.setItem("excalidraw-debug", '{"enabled":true}');
|
||||
localStorage.getItem("excalidraw-theme");
|
||||
localStorage.setItem("excalidraw-theme", "dark");
|
||||
localStorage.getItem("version-files");
|
||||
localStorage.setItem("version-files", "1756212319038");
|
||||
localStorage.getItem("version-dataState");
|
||||
localStorage.setItem("version-dataState", "1756212319038");
|
||||
localStorage.getItem("excalidraw-state");
|
||||
localStorage.setItem(
|
||||
"excalidraw-state",
|
||||
'{"showWelcomeScreen":true,"theme":"dark","currentChartType":"bar","currentItemBackgroundColor":"#a5d8ff","currentItemEndArrowhead":"arrow","currentItemFillStyle":"solid","currentItemFontFamily":5,"currentItemFontSize":20,"currentItemOpacity":100,"currentItemRoughness":2,"currentItemStartArrowhead":null,"currentItemStrokeColor":"#1e1e1e","currentItemRoundness":"round","currentItemArrowType":"round","currentItemStrokeStyle":"solid","currentItemStrokeWidth":2,"currentItemTextAlign":"left","cursorButton":"up","editingGroupId":null,"activeTool":{"type":"arrow","customType":null,"locked":false,"fromSelection":false,"lastActiveTool":null},"penMode":false,"penDetected":false,"exportBackground":true,"exportScale":1,"exportEmbedScene":false,"exportWithDarkMode":false,"gridSize":20,"gridStep":5,"gridModeEnabled":false,"defaultSidebarDockedPreference":false,"lastPointerDownWith":"mouse","name":"Untitled-2025-07-28-1603","openMenu":null,"openSidebar":null,"previousSelectedElementIds":{},"scrolledOutside":false,"scrollX":688.1079394457738,"scrollY":349.585883261872,"selectedElementIds":{},"selectedGroupIds":{},"shouldCacheIgnoreZoom":false,"stats":{"open":true,"panels":3},"viewBackgroundColor":"#ffffff","zenModeEnabled":false,"zoom":{"value":1.331666},"selectedLinearElement":null,"objectsSnapModeEnabled":false,"lockedMultiSelections":{}}',
|
||||
);
|
||||
localStorage.getItem("excalidraw");
|
||||
localStorage.setItem(
|
||||
"excalidraw",
|
||||
'[{"id":"hJuTw4QcwTsFtadNNnkLj","type":"rectangle","x":-100,"y":-100,"width":200,"height":200,"angle":0,"strokeColor":"#1e1e1e","backgroundColor":"#a5d8ff","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":1,"opacity":100,"groupIds":[],"frameId":null,"index":"a1","roundness":{"type":3},"seed":43277494,"version":839,"versionNonce":1923298088,"isDeleted":false,"boundElements":[{"id":"0xSZCPMN8RzKiJOpvGaKB","type":"arrow"}],"updated":1756212298830,"link":null,"locked":false},{"id":"qXw5KqKvAjHRr5uwPi9B-","type":"rectangle","x":-523.1841597523046,"y":-129.52451989693097,"width":200,"height":200,"angle":0,"strokeColor":"#1e1e1e","backgroundColor":"#a5d8ff","fillStyle":"solid","strokeWidth":2,"strokeStyle":"solid","roughness":1,"opacity":100,"groupIds":[],"frameId":null,"index":"a2","roundness":{"type":3},"seed":392633439,"version":963,"versionNonce":210394408,"isDeleted":false,"boundElements":[{"id":"0xSZCPMN8RzKiJOpvGaKB","type":"arrow"}],"updated":1756212298830,"link":null,"locked":false}]',
|
||||
);
|
||||
});
|
||||
await page.setViewportSize({ width: 1280, height: 1001 });
|
||||
await page.goto("http://localhost:3000");
|
||||
await page.waitForLoadState("load");
|
||||
await page.waitForTimeout(3.599999999627471);
|
||||
await page.mouse.move(425, 390);
|
||||
await page.waitForTimeout(9.900000000372529);
|
||||
await page.mouse.move(424, 390);
|
||||
await page.waitForTimeout(51.09999999962747);
|
||||
await page.mouse.move(423, 390);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(423, 392);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(422, 392);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(420, 393);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(420, 395);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(418, 395);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(417, 396);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(416, 396);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(416, 397);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(414, 397);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(414, 399);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(413, 399);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(413, 401);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(413, 402);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(411, 402);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(411, 403);
|
||||
await page.waitForTimeout(32);
|
||||
await page.mouse.move(412, 403);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(412, 403);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(412, 402);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(413, 402);
|
||||
await page.waitForTimeout(0.900000000372529);
|
||||
await page.mouse.move(413, 400);
|
||||
await page.waitForTimeout(1.099999999627471);
|
||||
await page.mouse.move(415, 400);
|
||||
await page.waitForTimeout(7);
|
||||
await page.mouse.move(416, 400);
|
||||
await page.waitForTimeout(71);
|
||||
await page.mouse.move(417, 400);
|
||||
await page.waitForTimeout(450);
|
||||
await page.mouse.move(417, 399);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(418, 399);
|
||||
await page.waitForTimeout(6.1000000005587935);
|
||||
await page.mouse.move(419, 399);
|
||||
await page.mouse.down({ button: "left" });
|
||||
await page.waitForTimeout(11.899999999441206);
|
||||
await page.mouse.move(420, 399);
|
||||
await page.waitForTimeout(69);
|
||||
await page.mouse.move(421, 399);
|
||||
await page.waitForTimeout(13);
|
||||
await page.mouse.move(422, 399);
|
||||
await page.waitForTimeout(7.1000000005587935);
|
||||
await page.mouse.move(423, 399);
|
||||
await page.waitForTimeout(5.3999999994412065);
|
||||
await page.mouse.move(425, 399);
|
||||
await page.waitForTimeout(0.5);
|
||||
await page.mouse.move(427, 401);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(428, 401);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(428, 403);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(430, 403);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(432, 403);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(432, 404);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(433, 404);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(434, 404);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(436, 406);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(437, 406);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(438, 407);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(440, 407);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(442, 407);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(443, 409);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(445, 409);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(447, 411);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(451, 411);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(455, 411);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(457, 413);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(459, 413);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(461, 415);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(463, 417);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(467, 419);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(469, 419);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(471, 420);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(473, 424);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(477, 424);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(477, 426);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(478, 426);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(482, 428);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(484, 430);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(486, 430);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(488, 430);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(488, 432);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(489, 432);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(491, 432);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(493, 434);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(495, 434);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(499, 436);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(501, 436);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(502, 436);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(504, 438);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(506, 440);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(508, 440);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(510, 442);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(512, 444);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(514, 444);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(514, 445);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(515, 445);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(517, 445);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(517, 447);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(519, 448);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(521, 448);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(522, 450);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(524, 450);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(525, 450);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(527, 450);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(529, 450);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(530, 450);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(532, 450);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(533, 451);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(534, 451);
|
||||
await page.waitForTimeout(3.1000000005587935);
|
||||
await page.mouse.move(535, 451);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(535, 453);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(537, 453);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(538, 453);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(540, 453);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(540, 454);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(541, 454);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(542, 454);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(543, 454);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(544, 454);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(544, 455);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(546, 455);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(547, 455);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(548, 455);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(549, 455);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(551, 455);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(552, 455);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(554, 455);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(555, 455);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(557, 455);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(559, 457);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(560, 457);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(562, 459);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(564, 459);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(566, 459);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(567, 459);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(569, 459);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(570, 459);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(574, 460);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(575, 460);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(575, 462);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(577, 464);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(578, 464);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(580, 464);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(582, 465);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(584, 465);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(585, 465);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(586, 465);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(588, 467);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(590, 467);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(591, 467);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(591, 468);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(594, 468);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(595, 468);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(597, 468);
|
||||
await page.waitForTimeout(2.7000000001862645);
|
||||
await page.mouse.move(601, 470);
|
||||
await page.waitForTimeout(1.400000000372529);
|
||||
await page.mouse.move(602, 470);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(603, 470);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(605, 470);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(607, 470);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(608, 470);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(610, 470);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(612, 470);
|
||||
await page.waitForTimeout(2.8999999994412065);
|
||||
await page.mouse.move(613, 470);
|
||||
await page.waitForTimeout(1.2000000001862645);
|
||||
await page.mouse.move(613, 471);
|
||||
await page.waitForTimeout(1.7999999998137355);
|
||||
await page.mouse.move(614, 471);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(616, 473);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(618, 473);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(621, 473);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(623, 473);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(625, 473);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(626, 473);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(628, 473);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(629, 473);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(631, 473);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(634, 475);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(636, 475);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(638, 475);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(639, 475);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(640, 475);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(642, 475);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(644, 475);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(647, 475);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(649, 475);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(650, 475);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(652, 475);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(653, 475);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(655, 475);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(656, 476);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(658, 476);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(659, 476);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(660, 476);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(662, 476);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(663, 476);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(664, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(666, 474);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(668, 474);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(670, 474);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(671, 474);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(673, 476);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(675, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(678, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(680, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(682, 476);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(683, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(684, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(686, 476);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(690, 476);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(694, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(696, 478);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(698, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(699, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(703, 478);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(705, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(707, 478);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(708, 478);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(711, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(713, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(714, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(716, 478);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(717, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(719, 478);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(722, 478);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(724, 478);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(725, 478);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(726, 478);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(727, 478);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(733, 480);
|
||||
await page.waitForTimeout(2.8999999994412065);
|
||||
await page.mouse.move(734, 480);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(735, 480);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(737, 480);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(739, 480);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(740, 480);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(742, 480);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(744, 480);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(744, 482);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(745, 482);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(747, 482);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(748, 482);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(749, 482);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(751, 482);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(753, 482);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(755, 482);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(758, 482);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(760, 482);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(761, 483);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(763, 484);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(765, 484);
|
||||
await page.waitForTimeout(2.8999999994412065);
|
||||
await page.mouse.move(766, 485);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(767, 485);
|
||||
await page.waitForTimeout(11);
|
||||
await page.mouse.move(768, 485);
|
||||
await page.waitForTimeout(12.100000000558794);
|
||||
await page.mouse.move(769, 485);
|
||||
await page.waitForTimeout(51.89999999944121);
|
||||
await page.mouse.move(770, 485);
|
||||
await page.waitForTimeout(9);
|
||||
await page.mouse.move(771, 485);
|
||||
await page.waitForTimeout(3.1000000005587935);
|
||||
await page.mouse.move(772, 485);
|
||||
await page.waitForTimeout(5);
|
||||
await page.mouse.move(773, 485);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(774, 485);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(776, 487);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(777, 487);
|
||||
await page.waitForTimeout(4.1000000005587935);
|
||||
await page.mouse.move(778, 487);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(779, 487);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(780, 488);
|
||||
await page.waitForTimeout(2.8999999994412065);
|
||||
await page.mouse.move(781, 488);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(782, 488);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(784, 488);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(785, 488);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(786, 488);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(788, 488);
|
||||
await page.waitForTimeout(8.899999999441206);
|
||||
await page.mouse.move(789, 488);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(790, 488);
|
||||
await page.waitForTimeout(5);
|
||||
await page.mouse.move(791, 488);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(792, 488);
|
||||
await page.waitForTimeout(6.1000000005587935);
|
||||
await page.mouse.move(793, 488);
|
||||
await page.waitForTimeout(3.8999999994412065);
|
||||
await page.mouse.move(793, 489);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(794, 489);
|
||||
await page.waitForTimeout(4.1000000005587935);
|
||||
await page.mouse.move(795, 489);
|
||||
await page.waitForTimeout(7.599999999627471);
|
||||
await page.mouse.move(796, 489);
|
||||
await page.waitForTimeout(3.400000000372529);
|
||||
await page.mouse.move(797, 489);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(798, 489);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(799, 489);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(800, 489);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(801, 489);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(802, 489);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(803, 489);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(804, 489);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(805, 489);
|
||||
await page.waitForTimeout(5.8999999994412065);
|
||||
await page.mouse.move(806, 490);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(807, 490);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(809, 490);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(810, 490);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(812, 490);
|
||||
await page.waitForTimeout(1.8999999994412065);
|
||||
await page.mouse.move(813, 490);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(815, 490);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(816, 492);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(818, 492);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(819, 492);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(820, 492);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(822, 492);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(823, 492);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(825, 492);
|
||||
await page.waitForTimeout(2.8999999994412065);
|
||||
await page.mouse.move(826, 492);
|
||||
await page.waitForTimeout(1.1000000005587935);
|
||||
await page.mouse.move(827, 492);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(828, 492);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(830, 492);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(831, 492);
|
||||
await page.waitForTimeout(2.1000000005587935);
|
||||
await page.mouse.move(832, 492);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(833, 493);
|
||||
await page.waitForTimeout(6.1000000005587935);
|
||||
await page.mouse.move(835, 493);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(836, 493);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(838, 493);
|
||||
await page.waitForTimeout(0.8999999994412065);
|
||||
await page.mouse.move(839, 493);
|
||||
await page.waitForTimeout(4.1000000005587935);
|
||||
await page.mouse.move(841, 493);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(842, 493);
|
||||
await page.waitForTimeout(3.8999999994412065);
|
||||
await page.mouse.move(843, 493);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(843, 492);
|
||||
await page.waitForTimeout(4.1000000005587935);
|
||||
await page.mouse.move(844, 492);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(844, 493);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(845, 493);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(846, 493);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(847, 494);
|
||||
await page.waitForTimeout(24.899999999441206);
|
||||
await page.mouse.move(847, 495);
|
||||
await page.waitForTimeout(29.100000000558794);
|
||||
await page.mouse.move(848, 495);
|
||||
await page.waitForTimeout(297.8999999994412);
|
||||
await page.mouse.move(848, 495);
|
||||
await page.waitForTimeout(5.7000000001862645);
|
||||
await page.mouse.up({ button: "left" });
|
||||
await expect(page).toHaveScreenshot({
|
||||
maxDiffPixels: 100,
|
||||
maxDiffPixelRatio: 0.01,
|
||||
});
|
||||
await page.waitForTimeout(11.299999999813735);
|
||||
await page.mouse.move(847, 495);
|
||||
await page.waitForTimeout(199.1000000005588);
|
||||
await page.mouse.move(847, 495);
|
||||
await page.waitForTimeout(249.29999999981374);
|
||||
await page.mouse.move(846, 495);
|
||||
await page.waitForTimeout(5.7000000001862645);
|
||||
await page.mouse.move(846, 496);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(845, 496);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(845, 497);
|
||||
await page.waitForTimeout(9);
|
||||
await page.mouse.move(845, 498);
|
||||
await page.waitForTimeout(3.8999999994412065);
|
||||
await page.mouse.move(844, 498);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(844, 500);
|
||||
await page.waitForTimeout(8);
|
||||
await page.mouse.move(844, 501);
|
||||
await page.waitForTimeout(3.1000000005587935);
|
||||
await page.mouse.move(843, 501);
|
||||
await page.waitForTimeout(137);
|
||||
await page.mouse.move(844, 501);
|
||||
await page.waitForTimeout(68.09999999962747);
|
||||
await page.mouse.move(845, 501);
|
||||
await page.waitForTimeout(7.7999999998137355);
|
||||
await page.mouse.move(845, 500);
|
||||
await page.waitForTimeout(1);
|
||||
await page.mouse.move(846, 500);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(847, 500);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(848, 500);
|
||||
await page.waitForTimeout(3.1000000005587935);
|
||||
await page.mouse.move(849, 500);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(850, 500);
|
||||
await page.waitForTimeout(5);
|
||||
await page.mouse.move(851, 500);
|
||||
await page.waitForTimeout(2);
|
||||
await page.mouse.move(852, 499);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(854, 499);
|
||||
await page.waitForTimeout(5);
|
||||
await page.mouse.move(855, 499);
|
||||
await page.waitForTimeout(3);
|
||||
await page.mouse.move(856, 499);
|
||||
await page.waitForTimeout(6);
|
||||
await page.mouse.move(857, 499);
|
||||
await page.waitForTimeout(12);
|
||||
await page.mouse.move(858, 499);
|
||||
await page.waitForTimeout(24);
|
||||
await page.mouse.move(858, 498);
|
||||
await page.waitForTimeout(4);
|
||||
await page.mouse.move(858, 498);
|
||||
await page.waitForTimeout(59.200000000186265);
|
||||
await page.keyboard.down("Control");
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 74 KiB |
@@ -11,9 +11,11 @@
|
||||
"@babel/preset-env": "7.26.9",
|
||||
"@excalidraw/eslint-config": "1.0.3",
|
||||
"@excalidraw/prettier-config": "1.0.2",
|
||||
"@playwright/test": "1.55.0",
|
||||
"@types/chai": "4.3.0",
|
||||
"@types/jest": "27.4.0",
|
||||
"@types/lodash.throttle": "4.1.7",
|
||||
"@types/node": "24.3.0",
|
||||
"@types/react": "19.0.10",
|
||||
"@types/react-dom": "19.0.4",
|
||||
"@types/socket.io-client": "3.0.0",
|
||||
@@ -62,6 +64,7 @@
|
||||
"build:preview": "yarn --cwd ./excalidraw-app build:preview",
|
||||
"start": "yarn --cwd ./excalidraw-app start",
|
||||
"start:production": "yarn --cwd ./excalidraw-app start:production",
|
||||
"start:test": "yarn --cwd ./excalidraw-app start:test",
|
||||
"start:example": "yarn build:packages && yarn --cwd ./examples/with-script-in-browser start",
|
||||
"test:all": "yarn test:typecheck && yarn test:code && yarn test:other && yarn test:app --watch=false",
|
||||
"test:app": "vitest",
|
||||
|
||||
@@ -5,18 +5,17 @@ export class BinaryHeap<T> {
|
||||
|
||||
sinkDown(idx: number) {
|
||||
const node = this.content[idx];
|
||||
const nodeScore = this.scoreFunction(node);
|
||||
while (idx > 0) {
|
||||
const parentN = ((idx + 1) >> 1) - 1;
|
||||
const parent = this.content[parentN];
|
||||
if (nodeScore < this.scoreFunction(parent)) {
|
||||
if (this.scoreFunction(node) < this.scoreFunction(parent)) {
|
||||
this.content[parentN] = node;
|
||||
this.content[idx] = parent;
|
||||
idx = parentN; // TODO: Optimize
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.content[idx] = node;
|
||||
}
|
||||
|
||||
bubbleUp(idx: number) {
|
||||
@@ -25,39 +24,35 @@ export class BinaryHeap<T> {
|
||||
const score = this.scoreFunction(node);
|
||||
|
||||
while (true) {
|
||||
const child1N = ((idx + 1) << 1) - 1;
|
||||
const child2N = child1N + 1;
|
||||
let smallestIdx = idx;
|
||||
let smallestScore = score;
|
||||
const child2N = (idx + 1) << 1;
|
||||
const child1N = child2N - 1;
|
||||
let swap = null;
|
||||
let child1Score = 0;
|
||||
|
||||
// Check left child
|
||||
if (child1N < length) {
|
||||
const child1Score = this.scoreFunction(this.content[child1N]);
|
||||
if (child1Score < smallestScore) {
|
||||
smallestIdx = child1N;
|
||||
smallestScore = child1Score;
|
||||
const child1 = this.content[child1N];
|
||||
child1Score = this.scoreFunction(child1);
|
||||
if (child1Score < score) {
|
||||
swap = child1N;
|
||||
}
|
||||
}
|
||||
|
||||
// Check right child
|
||||
if (child2N < length) {
|
||||
const child2Score = this.scoreFunction(this.content[child2N]);
|
||||
if (child2Score < smallestScore) {
|
||||
smallestIdx = child2N;
|
||||
const child2 = this.content[child2N];
|
||||
const child2Score = this.scoreFunction(child2);
|
||||
if (child2Score < (swap === null ? score : child1Score)) {
|
||||
swap = child2N;
|
||||
}
|
||||
}
|
||||
|
||||
if (smallestIdx === idx) {
|
||||
if (swap !== null) {
|
||||
this.content[idx] = this.content[swap];
|
||||
this.content[swap] = node;
|
||||
idx = swap; // TODO: Optimize
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
// Move the smaller child up, continue finding position for node
|
||||
this.content[idx] = this.content[smallestIdx];
|
||||
idx = smallestIdx;
|
||||
}
|
||||
|
||||
// Place node in its final position
|
||||
this.content[idx] = node;
|
||||
}
|
||||
|
||||
push(node: T) {
|
||||
|
||||
@@ -28,9 +28,11 @@ export const isBrave = () =>
|
||||
export const isMobile =
|
||||
isIOS ||
|
||||
/android|webos|ipod|blackberry|iemobile|opera mini/i.test(
|
||||
navigator.userAgent,
|
||||
navigator.userAgent.toLowerCase(),
|
||||
) ||
|
||||
/android|ios|ipod|blackberry|windows phone/i.test(navigator.platform);
|
||||
/android|ios|ipod|blackberry|windows phone/i.test(
|
||||
navigator.platform.toLowerCase(),
|
||||
);
|
||||
|
||||
export const supportsResizeObserver =
|
||||
typeof window !== "undefined" && "ResizeObserver" in window;
|
||||
@@ -125,12 +127,10 @@ export const ENV = {
|
||||
};
|
||||
|
||||
export const CLASSES = {
|
||||
SIDEBAR: "sidebar",
|
||||
SHAPE_ACTIONS_MENU: "App-menu__left",
|
||||
ZOOM_ACTIONS: "zoom-actions",
|
||||
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
||||
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
||||
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
||||
};
|
||||
|
||||
export const CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
||||
@@ -261,20 +261,13 @@ export const IMAGE_MIME_TYPES = {
|
||||
jfif: "image/jfif",
|
||||
} as const;
|
||||
|
||||
export const STRING_MIME_TYPES = {
|
||||
export const MIME_TYPES = {
|
||||
text: "text/plain",
|
||||
html: "text/html",
|
||||
json: "application/json",
|
||||
// excalidraw data
|
||||
excalidraw: "application/vnd.excalidraw+json",
|
||||
// LEGACY: fully-qualified library JSON data
|
||||
excalidrawlib: "application/vnd.excalidrawlib+json",
|
||||
// list of excalidraw library item ids
|
||||
excalidrawlibIds: "application/vnd.excalidrawlib.ids+json",
|
||||
} as const;
|
||||
|
||||
export const MIME_TYPES = {
|
||||
...STRING_MIME_TYPES,
|
||||
// image-encoded excalidraw data
|
||||
"excalidraw.svg": "image/svg+xml",
|
||||
"excalidraw.png": "image/png",
|
||||
@@ -351,20 +344,10 @@ export const DEFAULT_UI_OPTIONS: AppProps["UIOptions"] = {
|
||||
|
||||
// breakpoints
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// mobile: up to 699px
|
||||
export const MQ_MAX_MOBILE = 599;
|
||||
|
||||
// md screen
|
||||
export const MQ_MAX_WIDTH_PORTRAIT = 730;
|
||||
export const MQ_MAX_WIDTH_LANDSCAPE = 1000;
|
||||
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
|
||||
export const MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -442,9 +425,8 @@ export const ROUGHNESS = {
|
||||
|
||||
export const STROKE_WIDTH = {
|
||||
thin: 1,
|
||||
medium: 2,
|
||||
bold: 4,
|
||||
extraBold: 8,
|
||||
bold: 2,
|
||||
extraBold: 4,
|
||||
} as const;
|
||||
|
||||
export const DEFAULT_ELEMENT_PROPS: {
|
||||
@@ -460,7 +442,7 @@ export const DEFAULT_ELEMENT_PROPS: {
|
||||
strokeColor: COLOR_PALETTE.black,
|
||||
backgroundColor: COLOR_PALETTE.transparent,
|
||||
fillStyle: "solid",
|
||||
strokeWidth: STROKE_WIDTH.medium,
|
||||
strokeWidth: 2,
|
||||
strokeStyle: "solid",
|
||||
roughness: ROUGHNESS.artist,
|
||||
opacity: 100,
|
||||
@@ -542,10 +524,3 @@ export enum UserIdleState {
|
||||
* the start and end points)
|
||||
*/
|
||||
export const LINE_POLYGON_POINT_MERGE_DISTANCE = 20;
|
||||
|
||||
export const DOUBLE_TAP_POSITION_THRESHOLD = 35;
|
||||
|
||||
// glass background for mobile action buttons
|
||||
export const MOBILE_ACTION_BUTTON_BG = {
|
||||
background: "var(--mobile-action-button-bg)",
|
||||
} as const;
|
||||
|
||||
@@ -20,8 +20,7 @@ import {
|
||||
ENV,
|
||||
FONT_FAMILY,
|
||||
getFontFamilyFallbacks,
|
||||
isAndroid,
|
||||
isIOS,
|
||||
isDarwin,
|
||||
WINDOWS_EMOJI_FALLBACK_FONT,
|
||||
} from "./constants";
|
||||
|
||||
@@ -92,8 +91,7 @@ export const isWritableElement = (
|
||||
(target instanceof HTMLInputElement &&
|
||||
(target.type === "text" ||
|
||||
target.type === "number" ||
|
||||
target.type === "password" ||
|
||||
target.type === "search"));
|
||||
target.type === "password"));
|
||||
|
||||
export const getFontFamilyString = ({
|
||||
fontFamily,
|
||||
@@ -121,11 +119,6 @@ export const getFontString = ({
|
||||
return `${fontSize}px ${getFontFamilyString({ fontFamily })}` as FontString;
|
||||
};
|
||||
|
||||
/** executes callback in the frame that's after the current one */
|
||||
export const nextAnimationFrame = async (cb: () => any) => {
|
||||
requestAnimationFrame(() => requestAnimationFrame(cb));
|
||||
};
|
||||
|
||||
export const debounce = <T extends any[]>(
|
||||
fn: (...args: T) => void,
|
||||
timeout: number,
|
||||
@@ -425,6 +418,19 @@ export const allowFullScreen = () =>
|
||||
|
||||
export const exitFullScreen = () => document.exitFullscreen();
|
||||
|
||||
export const getShortcutKey = (shortcut: string): string => {
|
||||
shortcut = shortcut
|
||||
.replace(/\bAlt\b/i, "Alt")
|
||||
.replace(/\bShift\b/i, "Shift")
|
||||
.replace(/\b(Enter|Return)\b/i, "Enter");
|
||||
if (isDarwin) {
|
||||
return shortcut
|
||||
.replace(/\bCtrlOrCmd\b/gi, "Cmd")
|
||||
.replace(/\bAlt\b/i, "Option");
|
||||
}
|
||||
return shortcut.replace(/\bCtrlOrCmd\b/gi, "Ctrl");
|
||||
};
|
||||
|
||||
export const viewportCoordsToSceneCoords = (
|
||||
{ clientX, clientY }: { clientX: number; clientY: number },
|
||||
{
|
||||
@@ -1272,59 +1278,3 @@ export const reduceToCommonValue = <T, R = T>(
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -999,29 +999,6 @@ export const bindPointToSnapToElementOutline = (
|
||||
intersector,
|
||||
FIXED_BINDING_DISTANCE,
|
||||
).sort(pointDistanceSq)[0];
|
||||
|
||||
if (!intersection) {
|
||||
const anotherPoint = pointFrom<GlobalPoint>(
|
||||
!isHorizontal ? center[0] : snapPoint[0],
|
||||
isHorizontal ? center[1] : snapPoint[1],
|
||||
);
|
||||
const anotherIntersector = lineSegment(
|
||||
anotherPoint,
|
||||
pointFromVector(
|
||||
vectorScale(
|
||||
vectorNormalize(vectorFromPoint(snapPoint, anotherPoint)),
|
||||
Math.max(bindableElement.width, bindableElement.height) * 2,
|
||||
),
|
||||
anotherPoint,
|
||||
),
|
||||
);
|
||||
intersection = intersectElementWithLineSegment(
|
||||
bindableElement,
|
||||
elementsMap,
|
||||
anotherIntersector,
|
||||
FIXED_BINDING_DISTANCE,
|
||||
).sort(pointDistanceSq)[0];
|
||||
}
|
||||
} else {
|
||||
intersection = intersectElementWithLineSegment(
|
||||
bindableElement,
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
invariant,
|
||||
rescalePoints,
|
||||
sizeOf,
|
||||
STROKE_WIDTH,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import {
|
||||
@@ -43,7 +42,6 @@ import {
|
||||
isBoundToContainer,
|
||||
isFreeDrawElement,
|
||||
isLinearElement,
|
||||
isLineElement,
|
||||
isTextElement,
|
||||
} from "./typeChecks";
|
||||
|
||||
@@ -323,42 +321,19 @@ export const getElementLineSegments = (
|
||||
|
||||
if (shape.type === "polycurve") {
|
||||
const curves = shape.data;
|
||||
const pointsOnCurves = curves.map((curve) =>
|
||||
pointsOnBezierCurves(curve, 10),
|
||||
);
|
||||
|
||||
const points = curves
|
||||
.map((curve) => pointsOnBezierCurves(curve, 10))
|
||||
.flat();
|
||||
let i = 0;
|
||||
const segments: LineSegment<GlobalPoint>[] = [];
|
||||
|
||||
if (
|
||||
(isLineElement(element) && !element.polygon) ||
|
||||
isArrowElement(element)
|
||||
) {
|
||||
for (const points of pointsOnCurves) {
|
||||
let i = 0;
|
||||
|
||||
while (i < points.length - 1) {
|
||||
segments.push(
|
||||
lineSegment(
|
||||
pointFrom(points[i][0], points[i][1]),
|
||||
pointFrom(points[i + 1][0], points[i + 1][1]),
|
||||
),
|
||||
);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const points = pointsOnCurves.flat();
|
||||
let i = 0;
|
||||
|
||||
while (i < points.length - 1) {
|
||||
segments.push(
|
||||
lineSegment(
|
||||
pointFrom(points[i][0], points[i][1]),
|
||||
pointFrom(points[i + 1][0], points[i + 1][1]),
|
||||
),
|
||||
);
|
||||
i++;
|
||||
}
|
||||
while (i < points.length - 1) {
|
||||
segments.push(
|
||||
lineSegment(
|
||||
pointFrom(points[i][0], points[i][1]),
|
||||
pointFrom(points[i + 1][0], points[i + 1][1]),
|
||||
),
|
||||
);
|
||||
i++;
|
||||
}
|
||||
|
||||
return segments;
|
||||
@@ -833,15 +808,9 @@ export const getArrowheadPoints = (
|
||||
// This value is selected by minimizing a minimum size with the last segment of the arrowhead
|
||||
const lengthMultiplier =
|
||||
arrowhead === "diamond" || arrowhead === "diamond_outline" ? 0.25 : 0.5;
|
||||
// make arrowheads bigger for thick strokes
|
||||
const strokeWidthMultiplier =
|
||||
element.strokeWidth >= STROKE_WIDTH.extraBold ? 1.5 : 1;
|
||||
|
||||
const adjustedSize =
|
||||
Math.min(size, length * lengthMultiplier) * strokeWidthMultiplier;
|
||||
|
||||
const xs = x2 - nx * adjustedSize;
|
||||
const ys = y2 - ny * adjustedSize;
|
||||
const minSize = Math.min(size, length * lengthMultiplier);
|
||||
const xs = x2 - nx * minSize;
|
||||
const ys = y2 - ny * minSize;
|
||||
|
||||
if (
|
||||
arrowhead === "dot" ||
|
||||
@@ -890,7 +859,7 @@ export const getArrowheadPoints = (
|
||||
const [px, py] = element.points.length > 1 ? element.points[1] : [0, 0];
|
||||
|
||||
[ox, oy] = pointRotateRads(
|
||||
pointFrom(x2 + adjustedSize * 2, y2),
|
||||
pointFrom(x2 + minSize * 2, y2),
|
||||
pointFrom(x2, y2),
|
||||
Math.atan2(py - y2, px - x2) as Radians,
|
||||
);
|
||||
@@ -901,7 +870,7 @@ export const getArrowheadPoints = (
|
||||
: [0, 0];
|
||||
|
||||
[ox, oy] = pointRotateRads(
|
||||
pointFrom(x2 - adjustedSize * 2, y2),
|
||||
pointFrom(x2 - minSize * 2, y2),
|
||||
pointFrom(x2, y2),
|
||||
Math.atan2(y2 - py, x2 - px) as Radians,
|
||||
);
|
||||
@@ -1157,9 +1126,7 @@ export interface BoundingBox {
|
||||
}
|
||||
|
||||
export const getCommonBoundingBox = (
|
||||
elements:
|
||||
| readonly ExcalidrawElement[]
|
||||
| readonly NonDeleted<ExcalidrawElement>[],
|
||||
elements: ExcalidrawElement[] | readonly NonDeleted<ExcalidrawElement>[],
|
||||
): BoundingBox => {
|
||||
const [minX, minY, maxX, maxY] = getCommonBounds(elements);
|
||||
return {
|
||||
|
||||
@@ -10,13 +10,7 @@ export const hasBackground = (type: ElementOrToolType) =>
|
||||
type === "freedraw";
|
||||
|
||||
export const hasStrokeColor = (type: ElementOrToolType) =>
|
||||
type === "rectangle" ||
|
||||
type === "ellipse" ||
|
||||
type === "diamond" ||
|
||||
type === "freedraw" ||
|
||||
type === "arrow" ||
|
||||
type === "line" ||
|
||||
type === "text";
|
||||
type !== "image" && type !== "frame" && type !== "magicframe";
|
||||
|
||||
export const hasStrokeWidth = (type: ElementOrToolType) =>
|
||||
type === "rectangle" ||
|
||||
|
||||
@@ -1111,16 +1111,16 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
||||
inserted,
|
||||
}: Delta<ElementPartial>) =>
|
||||
!!(
|
||||
deleted.version &&
|
||||
inserted.version &&
|
||||
// versions are required integers
|
||||
(
|
||||
Number.isInteger(deleted.version) &&
|
||||
Number.isInteger(inserted.version) &&
|
||||
// versions should be positive, zero included
|
||||
deleted.version! >= 0 &&
|
||||
inserted.version! >= 0 &&
|
||||
// versions should never be the same
|
||||
deleted.version !== inserted.version
|
||||
)
|
||||
Number.isInteger(deleted.version) &&
|
||||
Number.isInteger(inserted.version) &&
|
||||
// versions should be positive, zero included
|
||||
deleted.version >= 0 &&
|
||||
inserted.version >= 0 &&
|
||||
// versions should never be the same
|
||||
deleted.version !== inserted.version
|
||||
);
|
||||
|
||||
private static satisfiesUniqueInvariants = (
|
||||
@@ -1191,10 +1191,9 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
||||
ElementsDelta.stripIrrelevantProps,
|
||||
);
|
||||
|
||||
// ignore updates which would "delete" already deleted element
|
||||
if (!prevElement.isDeleted) {
|
||||
removed[prevElement.id] = delta;
|
||||
} else {
|
||||
updated[prevElement.id] = delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1222,8 +1221,6 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
||||
// ignore updates which would "delete" already deleted element
|
||||
if (!nextElement.isDeleted) {
|
||||
added[nextElement.id] = delta;
|
||||
} else {
|
||||
updated[nextElement.id] = delta;
|
||||
}
|
||||
|
||||
continue;
|
||||
@@ -1253,7 +1250,15 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
||||
continue;
|
||||
}
|
||||
|
||||
updated[nextElement.id] = delta;
|
||||
const strippedDeleted = ElementsDelta.stripVersionProps(delta.deleted);
|
||||
const strippedInserted = ElementsDelta.stripVersionProps(
|
||||
delta.inserted,
|
||||
);
|
||||
|
||||
// making sure there are at least some changes and only changed version & versionNonce does not count!
|
||||
if (Delta.isInnerDifferent(strippedDeleted, strippedInserted, true)) {
|
||||
updated[nextElement.id] = delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1367,8 +1372,15 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
||||
latestDelta = delta;
|
||||
}
|
||||
|
||||
const strippedDeleted = ElementsDelta.stripVersionProps(
|
||||
latestDelta.deleted,
|
||||
);
|
||||
const strippedInserted = ElementsDelta.stripVersionProps(
|
||||
latestDelta.inserted,
|
||||
);
|
||||
|
||||
// it might happen that after applying latest changes the delta itself does not contain any changes
|
||||
if (Delta.isInnerDifferent(latestDelta.deleted, latestDelta.inserted)) {
|
||||
if (Delta.isInnerDifferent(strippedDeleted, strippedInserted)) {
|
||||
modifiedDeltas[id] = latestDelta;
|
||||
}
|
||||
}
|
||||
@@ -2063,4 +2075,12 @@ export class ElementsDelta implements DeltaContainer<SceneElementsMap> {
|
||||
|
||||
return strippedPartial;
|
||||
}
|
||||
|
||||
private static stripVersionProps(
|
||||
partial: Partial<OrderedExcalidrawElement>,
|
||||
): ElementPartial {
|
||||
const { version, versionNonce, ...strippedPartial } = partial;
|
||||
|
||||
return strippedPartial;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,12 +359,6 @@ const handleSegmentRelease = (
|
||||
null,
|
||||
);
|
||||
|
||||
if (!restoredPoints || restoredPoints.length < 2) {
|
||||
throw new Error(
|
||||
"Property 'points' is required in the update returned by normalizeArrowElementUpdate()",
|
||||
);
|
||||
}
|
||||
|
||||
const nextPoints: GlobalPoint[] = [];
|
||||
|
||||
// First part of the arrow are the old points
|
||||
@@ -712,7 +706,7 @@ const handleEndpointDrag = (
|
||||
endGlobalPoint: GlobalPoint,
|
||||
hoveredStartElement: ExcalidrawBindableElement | null,
|
||||
hoveredEndElement: ExcalidrawBindableElement | null,
|
||||
): ElementUpdate<ExcalidrawElbowArrowElement> => {
|
||||
) => {
|
||||
let startIsSpecial = arrow.startIsSpecial ?? null;
|
||||
let endIsSpecial = arrow.endIsSpecial ?? null;
|
||||
const globalUpdatedPoints = updatedPoints.map((p, i) =>
|
||||
@@ -747,15 +741,8 @@ const handleEndpointDrag = (
|
||||
|
||||
// Calculate the moving second point connection and add the start point
|
||||
{
|
||||
const secondPoint = globalUpdatedPoints.at(startIsSpecial ? 2 : 1);
|
||||
const thirdPoint = globalUpdatedPoints.at(startIsSpecial ? 3 : 2);
|
||||
|
||||
if (!secondPoint || !thirdPoint) {
|
||||
throw new Error(
|
||||
`Second and third points must exist when handling endpoint drag (${startIsSpecial})`,
|
||||
);
|
||||
}
|
||||
|
||||
const secondPoint = globalUpdatedPoints[startIsSpecial ? 2 : 1];
|
||||
const thirdPoint = globalUpdatedPoints[startIsSpecial ? 3 : 2];
|
||||
const startIsHorizontal = headingIsHorizontal(startHeading);
|
||||
const secondIsHorizontal = headingIsHorizontal(
|
||||
vectorToHeading(vectorFromPoint(secondPoint, thirdPoint)),
|
||||
@@ -814,19 +801,10 @@ const handleEndpointDrag = (
|
||||
|
||||
// Calculate the moving second to last point connection
|
||||
{
|
||||
const secondToLastPoint = globalUpdatedPoints.at(
|
||||
globalUpdatedPoints.length - (endIsSpecial ? 3 : 2),
|
||||
);
|
||||
const thirdToLastPoint = globalUpdatedPoints.at(
|
||||
globalUpdatedPoints.length - (endIsSpecial ? 4 : 3),
|
||||
);
|
||||
|
||||
if (!secondToLastPoint || !thirdToLastPoint) {
|
||||
throw new Error(
|
||||
`Second and third to last points must exist when handling endpoint drag (${endIsSpecial})`,
|
||||
);
|
||||
}
|
||||
|
||||
const secondToLastPoint =
|
||||
globalUpdatedPoints[globalUpdatedPoints.length - (endIsSpecial ? 3 : 2)];
|
||||
const thirdToLastPoint =
|
||||
globalUpdatedPoints[globalUpdatedPoints.length - (endIsSpecial ? 4 : 3)];
|
||||
const endIsHorizontal = headingIsHorizontal(endHeading);
|
||||
const secondIsHorizontal = headingForPointIsHorizontal(
|
||||
thirdToLastPoint,
|
||||
@@ -2093,7 +2071,16 @@ const normalizeArrowElementUpdate = (
|
||||
nextFixedSegments: readonly FixedSegment[] | null,
|
||||
startIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"],
|
||||
endIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"],
|
||||
): ElementUpdate<ExcalidrawElbowArrowElement> => {
|
||||
): {
|
||||
points: LocalPoint[];
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
fixedSegments: readonly FixedSegment[] | null;
|
||||
startIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"];
|
||||
endIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"];
|
||||
} => {
|
||||
const offsetX = global[0][0];
|
||||
const offsetY = global[0][1];
|
||||
let points = global.map((p) =>
|
||||
|
||||
@@ -1,373 +0,0 @@
|
||||
import { LaserPointer, type Point } from "@excalidraw/laser-pointer";
|
||||
|
||||
import {
|
||||
clamp,
|
||||
lineSegment,
|
||||
pointFrom,
|
||||
pointRotateRads,
|
||||
round,
|
||||
type LocalPoint,
|
||||
} from "@excalidraw/math";
|
||||
|
||||
import getStroke from "perfect-freehand";
|
||||
|
||||
import { invariant } from "@excalidraw/common";
|
||||
|
||||
import type { GlobalPoint, Radians } from "@excalidraw/math";
|
||||
|
||||
import { getElementBounds } from "./bounds";
|
||||
|
||||
import type { StrokeOptions } from "perfect-freehand";
|
||||
|
||||
import type {
|
||||
ElementsMap,
|
||||
ExcalidrawFreeDrawElement,
|
||||
PointerType,
|
||||
} from "./types";
|
||||
|
||||
export const STROKE_OPTIONS: Record<
|
||||
PointerType | "default",
|
||||
{ streamline: number; simplify: number }
|
||||
> = {
|
||||
default: {
|
||||
streamline: 0.35,
|
||||
simplify: 0.1,
|
||||
},
|
||||
mouse: {
|
||||
streamline: 0.6,
|
||||
simplify: 0.1,
|
||||
},
|
||||
pen: {
|
||||
// for optimal performance, we use a lower streamline and simplify
|
||||
streamline: 0.2,
|
||||
simplify: 0.1,
|
||||
},
|
||||
touch: {
|
||||
streamline: 0.65,
|
||||
simplify: 0.1,
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const getFreedrawConfig = (eventType: string | null | undefined) => {
|
||||
return (
|
||||
STROKE_OPTIONS[(eventType as PointerType | null) || "default"] ||
|
||||
STROKE_OPTIONS.default
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates simulated pressure based on velocity between consecutive points.
|
||||
* Fast movement (large distances) -> lower pressure
|
||||
* Slow movement (small distances) -> higher pressure
|
||||
*/
|
||||
const calculateVelocityBasedPressure = (
|
||||
points: readonly LocalPoint[],
|
||||
index: number,
|
||||
fixedStrokeWidth: boolean | undefined,
|
||||
maxDistance = 8, // Maximum expected distance for normalization
|
||||
): number => {
|
||||
if (fixedStrokeWidth) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// First point gets highest pressure
|
||||
// This avoid "a dot followed by a line" effect, •== when first stroke is "slow"
|
||||
if (index === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const [x1, y1] = points[index - 1];
|
||||
const [x2, y2] = points[index];
|
||||
|
||||
// Calculate distance between consecutive points
|
||||
const distance = Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
|
||||
|
||||
// Normalize distance and invert for pressure (0 = fast/low pressure, 1 = slow/high pressure)
|
||||
const normalizedDistance = Math.min(distance / maxDistance, 1);
|
||||
const basePressure = Math.max(0.1, 1 - normalizedDistance * 0.7); // Range: 0.1 to 1.0
|
||||
|
||||
const constantPressure = 0.5;
|
||||
const pressure = constantPressure + (basePressure - constantPressure);
|
||||
|
||||
return Math.max(0.1, Math.min(1.0, pressure));
|
||||
};
|
||||
|
||||
export const getFreedrawStroke = (element: ExcalidrawFreeDrawElement) => {
|
||||
// Compose points as [x, y, pressure]
|
||||
let points: [number, number, number][];
|
||||
if (element.freedrawOptions?.fixedStrokeWidth) {
|
||||
points = element.points.map(
|
||||
([x, y]: LocalPoint): [number, number, number] => [x, y, 1],
|
||||
);
|
||||
} else if (element.simulatePressure) {
|
||||
// Simulate pressure based on velocity between consecutive points
|
||||
points = element.points.map(([x, y]: LocalPoint, i) => [
|
||||
x,
|
||||
y,
|
||||
calculateVelocityBasedPressure(
|
||||
element.points,
|
||||
i,
|
||||
element.freedrawOptions?.fixedStrokeWidth,
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
points = element.points.map(([x, y]: LocalPoint, i) => {
|
||||
const rawPressure = element.pressures?.[i] ?? 0.5;
|
||||
|
||||
const amplifiedPressure = Math.pow(rawPressure, 0.6);
|
||||
const adjustedPressure = amplifiedPressure;
|
||||
|
||||
return [x, y, clamp(adjustedPressure, 0.1, 1.0)];
|
||||
});
|
||||
}
|
||||
|
||||
const streamline =
|
||||
element.freedrawOptions?.streamline ?? STROKE_OPTIONS.default.streamline;
|
||||
const simplify =
|
||||
element.freedrawOptions?.simplify ?? STROKE_OPTIONS.default.simplify;
|
||||
|
||||
const laser = new LaserPointer({
|
||||
size: element.strokeWidth,
|
||||
streamline,
|
||||
simplify,
|
||||
sizeMapping: ({ pressure: t }) => {
|
||||
if (element.freedrawOptions?.fixedStrokeWidth) {
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
if (element.simulatePressure) {
|
||||
return 0.2 + t * 0.6;
|
||||
}
|
||||
|
||||
return 0.2 + t * 0.8;
|
||||
},
|
||||
});
|
||||
|
||||
for (const pt of points) {
|
||||
laser.addPoint(pt);
|
||||
}
|
||||
laser.close();
|
||||
|
||||
return laser.getStrokeOutline();
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates an SVG path for a freedraw element using LaserPointer logic.
|
||||
* Uses actual pressure data if available, otherwise simulates pressure based on velocity.
|
||||
* No streamline, smoothing, or simulation is performed.
|
||||
*/
|
||||
export const getFreeDrawSvgPath = (
|
||||
element: ExcalidrawFreeDrawElement,
|
||||
): string => {
|
||||
// legacy, for backwards compatibility
|
||||
if (element.freedrawOptions === null) {
|
||||
return _legacy_getFreeDrawSvgPath(element);
|
||||
}
|
||||
|
||||
return _transition_getFreeDrawSvgPath(element);
|
||||
|
||||
// return getSvgPathFromStroke(getFreedrawStroke(element));
|
||||
};
|
||||
|
||||
const roundPoint = (A: Point): string => {
|
||||
return `${round(A[0], 4, "round")},${round(A[1], 4, "round")} `;
|
||||
};
|
||||
|
||||
const average = (A: Point, B: Point): string => {
|
||||
return `${round((A[0] + B[0]) / 2, 4, "round")},${round(
|
||||
(A[1] + B[1]) / 2,
|
||||
4,
|
||||
"round",
|
||||
)} `;
|
||||
};
|
||||
|
||||
export const getSvgPathFromStroke = (points: Point[]): string => {
|
||||
const len = points.length;
|
||||
|
||||
if (len < 2) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let a = points[0];
|
||||
let b = points[1];
|
||||
|
||||
if (len === 2) {
|
||||
return `M${roundPoint(a)}L${roundPoint(b)}`;
|
||||
}
|
||||
|
||||
let result = "";
|
||||
|
||||
for (let i = 2, max = len - 1; i < max; i++) {
|
||||
a = points[i];
|
||||
b = points[i + 1];
|
||||
result += average(a, b);
|
||||
}
|
||||
|
||||
return `M${roundPoint(points[0])}Q${roundPoint(points[1])}${average(
|
||||
points[1],
|
||||
points[2],
|
||||
)}${points.length > 3 ? "T" : ""}${result}L${roundPoint(points[len - 1])}`;
|
||||
};
|
||||
|
||||
function _transition_getFreeDrawSvgPath(element: ExcalidrawFreeDrawElement) {
|
||||
const inputPoints = element.simulatePressure
|
||||
? element.points
|
||||
: element.points.length
|
||||
? element.points.map(([x, y], i) => [x, y, element.pressures[i]])
|
||||
: [[0, 0, 0.5]];
|
||||
|
||||
// Consider changing the options for simulated pressure vs real pressure
|
||||
const options: StrokeOptions = {
|
||||
simulatePressure: element.simulatePressure,
|
||||
size: element.strokeWidth,
|
||||
thinning: 0.6,
|
||||
smoothing: 0.5,
|
||||
streamline: 0.5,
|
||||
easing: (t) => {
|
||||
if (element.freedrawOptions?.fixedStrokeWidth) {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
return Math.sin((t * Math.PI) / 2) * 0.65;
|
||||
}, // https://easings.net/#easeOutSine
|
||||
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
||||
};
|
||||
|
||||
return _legacy_getSvgPathFromStroke(
|
||||
getStroke(inputPoints as number[][], options),
|
||||
);
|
||||
}
|
||||
|
||||
function _legacy_getFreeDrawSvgPath(element: ExcalidrawFreeDrawElement) {
|
||||
// If input points are empty (should they ever be?) return a dot
|
||||
const inputPoints = element.simulatePressure
|
||||
? element.points
|
||||
: element.points.length
|
||||
? element.points.map(([x, y], i) => [x, y, element.pressures[i]])
|
||||
: [[0, 0, 0.5]];
|
||||
|
||||
// Consider changing the options for simulated pressure vs real pressure
|
||||
const options: StrokeOptions = {
|
||||
simulatePressure: element.simulatePressure,
|
||||
size: element.strokeWidth * 4.25,
|
||||
thinning: 0.6,
|
||||
smoothing: 0.5,
|
||||
streamline: 0.5,
|
||||
easing: (t) => Math.sin((t * Math.PI) / 2), // https://easings.net/#easeOutSine
|
||||
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
||||
};
|
||||
|
||||
return _legacy_getSvgPathFromStroke(
|
||||
getStroke(inputPoints as number[][], options),
|
||||
);
|
||||
}
|
||||
|
||||
const med = (A: number[], B: number[]) => {
|
||||
return [(A[0] + B[0]) / 2, (A[1] + B[1]) / 2];
|
||||
};
|
||||
|
||||
// Trim SVG path data so number are each two decimal points. This
|
||||
// improves SVG exports, and prevents rendering errors on points
|
||||
// with long decimals.
|
||||
const TO_FIXED_PRECISION = /(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;
|
||||
|
||||
const _legacy_getSvgPathFromStroke = (points: number[][]): string => {
|
||||
if (!points.length) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const max = points.length - 1;
|
||||
|
||||
return points
|
||||
.reduce(
|
||||
(acc, point, i, arr) => {
|
||||
if (i === max) {
|
||||
acc.push(point, med(point, arr[0]), "L", arr[0], "Z");
|
||||
} else {
|
||||
acc.push(point, med(point, arr[i + 1]));
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
["M", points[0], "Q"],
|
||||
)
|
||||
.join(" ")
|
||||
.replace(TO_FIXED_PRECISION, "$1");
|
||||
};
|
||||
|
||||
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
|
||||
const inputPoints = element.simulatePressure
|
||||
? element.points
|
||||
: element.points.length
|
||||
? element.points.map(([x, y], i) => [x, y, element.pressures[i]])
|
||||
: [[0, 0, 0.5]];
|
||||
|
||||
// Consider changing the options for simulated pressure vs real pressure
|
||||
const options: StrokeOptions = {
|
||||
simulatePressure: element.simulatePressure,
|
||||
size: element.strokeWidth * 4.25,
|
||||
thinning: 0.6,
|
||||
smoothing: 0.5,
|
||||
streamline: 0.5,
|
||||
easing: (t) => Math.sin((t * Math.PI) / 2), // https://easings.net/#easeOutSine
|
||||
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
||||
};
|
||||
|
||||
return getStroke(inputPoints as number[][], options) as [number, number][];
|
||||
}
|
||||
@@ -29,9 +29,6 @@ export const hashElementsVersion = (elements: ElementsMapOrArray): number => {
|
||||
|
||||
// string hash function (using djb2). Not cryptographically secure, use only
|
||||
// for versioning and such.
|
||||
// note: hashes individual code units (not code points),
|
||||
// but for hashing purposes this is fine as it iterates through every code unit
|
||||
// (as such, no need to encode to byte string first)
|
||||
export const hashString = (s: string): number => {
|
||||
let hash: number = 5381;
|
||||
for (let i = 0; i < s.length; i++) {
|
||||
@@ -94,14 +91,12 @@ export * from "./embeddable";
|
||||
export * from "./flowchart";
|
||||
export * from "./fractionalIndex";
|
||||
export * from "./frame";
|
||||
export * from "./freedraw";
|
||||
export * from "./groups";
|
||||
export * from "./heading";
|
||||
export * from "./image";
|
||||
export * from "./linearElementEditor";
|
||||
export * from "./mutateElement";
|
||||
export * from "./newElement";
|
||||
export * from "./positionElementsOnGrid";
|
||||
export * from "./renderElement";
|
||||
export * from "./resizeElements";
|
||||
export * from "./resizeTest";
|
||||
|
||||
@@ -445,7 +445,6 @@ export const newFreeDrawElement = (
|
||||
points?: ExcalidrawFreeDrawElement["points"];
|
||||
simulatePressure: boolean;
|
||||
pressures?: ExcalidrawFreeDrawElement["pressures"];
|
||||
strokeOptions?: ExcalidrawFreeDrawElement["freedrawOptions"];
|
||||
} & ElementConstructorOpts,
|
||||
): NonDeleted<ExcalidrawFreeDrawElement> => {
|
||||
return {
|
||||
@@ -454,11 +453,6 @@ export const newFreeDrawElement = (
|
||||
pressures: opts.pressures || [],
|
||||
simulatePressure: opts.simulatePressure,
|
||||
lastCommittedPoint: null,
|
||||
freedrawOptions: opts.strokeOptions || {
|
||||
fixedStrokeWidth: true,
|
||||
streamline: 0.25,
|
||||
simplify: 0.1,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
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,4 +1,5 @@
|
||||
import rough from "roughjs/bin/rough";
|
||||
import { getStroke } from "perfect-freehand";
|
||||
|
||||
import { isRightAngleRads } from "@excalidraw/math";
|
||||
|
||||
@@ -57,8 +58,6 @@ import { getCornerRadius } from "./utils";
|
||||
|
||||
import { ShapeCache } from "./shape";
|
||||
|
||||
import { getFreeDrawSvgPath } from "./freedraw";
|
||||
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawTextElement,
|
||||
@@ -71,6 +70,7 @@ import type {
|
||||
ElementsMap,
|
||||
} from "./types";
|
||||
|
||||
import type { StrokeOptions } from "perfect-freehand";
|
||||
import type { RoughCanvas } from "roughjs/bin/canvas";
|
||||
|
||||
// using a stronger invert (100% vs our regular 93%) and saturate
|
||||
@@ -1037,3 +1037,57 @@ export function generateFreeDrawShape(element: ExcalidrawFreeDrawElement) {
|
||||
export function getFreeDrawPath2D(element: ExcalidrawFreeDrawElement) {
|
||||
return pathsCache.get(element);
|
||||
}
|
||||
|
||||
export function getFreeDrawSvgPath(element: ExcalidrawFreeDrawElement) {
|
||||
// If input points are empty (should they ever be?) return a dot
|
||||
const inputPoints = element.simulatePressure
|
||||
? element.points
|
||||
: element.points.length
|
||||
? element.points.map(([x, y], i) => [x, y, element.pressures[i]])
|
||||
: [[0, 0, 0.5]];
|
||||
|
||||
// Consider changing the options for simulated pressure vs real pressure
|
||||
const options: StrokeOptions = {
|
||||
simulatePressure: element.simulatePressure,
|
||||
size: element.strokeWidth * 4.25,
|
||||
thinning: 0.6,
|
||||
smoothing: 0.5,
|
||||
streamline: 0.5,
|
||||
easing: (t) => Math.sin((t * Math.PI) / 2), // https://easings.net/#easeOutSine
|
||||
last: !!element.lastCommittedPoint, // LastCommittedPoint is added on pointerup
|
||||
};
|
||||
|
||||
return getSvgPathFromStroke(getStroke(inputPoints as number[][], options));
|
||||
}
|
||||
|
||||
function med(A: number[], B: number[]) {
|
||||
return [(A[0] + B[0]) / 2, (A[1] + B[1]) / 2];
|
||||
}
|
||||
|
||||
// Trim SVG path data so number are each two decimal points. This
|
||||
// improves SVG exports, and prevents rendering errors on points
|
||||
// with long decimals.
|
||||
const TO_FIXED_PRECISION = /(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;
|
||||
|
||||
function getSvgPathFromStroke(points: number[][]): string {
|
||||
if (!points.length) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const max = points.length - 1;
|
||||
|
||||
return points
|
||||
.reduce(
|
||||
(acc, point, i, arr) => {
|
||||
if (i === max) {
|
||||
acc.push(point, med(point, arr[0]), "L", arr[0], "Z");
|
||||
} else {
|
||||
acc.push(point, med(point, arr[i + 1]));
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
["M", points[0], "Q"],
|
||||
)
|
||||
.join(" ")
|
||||
.replace(TO_FIXED_PRECISION, "$1");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
getContainerElement,
|
||||
handleBindTextResize,
|
||||
getBoundTextMaxWidth,
|
||||
computeBoundTextPosition,
|
||||
} from "./textElement";
|
||||
import {
|
||||
getMinTextElementWidth,
|
||||
@@ -226,16 +225,7 @@ const rotateSingleElement = (
|
||||
scene.getElement<ExcalidrawTextElementWithContainer>(boundTextElementId);
|
||||
|
||||
if (textElement && !isArrowElement(element)) {
|
||||
const { x, y } = computeBoundTextPosition(
|
||||
element,
|
||||
textElement,
|
||||
scene.getNonDeletedElementsMap(),
|
||||
);
|
||||
scene.mutateElement(textElement, {
|
||||
angle,
|
||||
x,
|
||||
y,
|
||||
});
|
||||
scene.mutateElement(textElement, { angle });
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -426,15 +416,9 @@ const rotateMultipleElements = (
|
||||
|
||||
const boundText = getBoundTextElement(element, elementsMap);
|
||||
if (boundText && !isArrowElement(element)) {
|
||||
const { x, y } = computeBoundTextPosition(
|
||||
element,
|
||||
boundText,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
scene.mutateElement(boundText, {
|
||||
x,
|
||||
y,
|
||||
x: boundText.x + (rotatedCX - cx),
|
||||
y: boundText.y + (rotatedCY - cy),
|
||||
angle: normalizeRadians((centerAngle + origAngle) as Radians),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
assertNever,
|
||||
COLOR_PALETTE,
|
||||
LINE_POLYGON_POINT_MERGE_DISTANCE,
|
||||
STROKE_WIDTH,
|
||||
isTestEnv,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { RoughGenerator } from "roughjs/bin/generator";
|
||||
@@ -183,7 +183,7 @@ export const generateRoughOptions = (
|
||||
continuousPath = false,
|
||||
): Options => {
|
||||
const options: Options = {
|
||||
seed: element.seed,
|
||||
seed: isTestEnv() ? 1 : element.seed,
|
||||
strokeLineDash:
|
||||
element.strokeStyle === "dashed"
|
||||
? getDashArrayDashed(element.strokeWidth)
|
||||
@@ -203,7 +203,7 @@ export const generateRoughOptions = (
|
||||
// hachureGap because if not specified, roughjs uses strokeWidth to
|
||||
// calculate them (and we don't want the fills to be modified)
|
||||
fillWeight: element.strokeWidth / 2,
|
||||
hachureGap: Math.min(element.strokeWidth, STROKE_WIDTH.bold) * 4,
|
||||
hachureGap: element.strokeWidth * 4,
|
||||
roughness: adjustRoughness(element),
|
||||
stroke: element.strokeColor,
|
||||
preserveVertices:
|
||||
@@ -807,21 +807,15 @@ const generateElementShape = (
|
||||
generateFreeDrawShape(element);
|
||||
|
||||
if (isPathALoop(element.points)) {
|
||||
const points =
|
||||
element.freedrawOptions === null
|
||||
? simplify(element.points as LocalPoint[], 0.75)
|
||||
: simplify(element.points as LocalPoint[], 1.5);
|
||||
|
||||
shape =
|
||||
element.freedrawOptions === null
|
||||
? generator.curve(points, {
|
||||
...generateRoughOptions(element),
|
||||
stroke: "none",
|
||||
})
|
||||
: generator.polygon(points, {
|
||||
...generateRoughOptions(element),
|
||||
stroke: "none",
|
||||
});
|
||||
// generate rough polygon to fill freedraw shape
|
||||
const simplifiedPoints = simplify(
|
||||
element.points as Mutable<LocalPoint[]>,
|
||||
0.75,
|
||||
);
|
||||
shape = generator.curve(simplifiedPoints as [number, number][], {
|
||||
...generateRoughOptions(element),
|
||||
stroke: "none",
|
||||
});
|
||||
} else {
|
||||
shape = null;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ import {
|
||||
invariant,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { pointFrom, pointRotateRads, type Radians } from "@excalidraw/math";
|
||||
|
||||
import type { AppState } from "@excalidraw/excalidraw/types";
|
||||
|
||||
import type { ExtractSetType } from "@excalidraw/common/utility-types";
|
||||
|
||||
import type { Radians } from "@excalidraw/math";
|
||||
|
||||
import {
|
||||
resetOriginalContainerCache,
|
||||
updateOriginalContainerCache,
|
||||
@@ -254,26 +254,6 @@ export const computeBoundTextPosition = (
|
||||
x =
|
||||
containerCoords.x + (maxContainerWidth / 2 - boundTextElement.width / 2);
|
||||
}
|
||||
const angle = (container.angle ?? 0) as Radians;
|
||||
|
||||
if (angle !== 0) {
|
||||
const contentCenter = pointFrom(
|
||||
containerCoords.x + maxContainerWidth / 2,
|
||||
containerCoords.y + maxContainerHeight / 2,
|
||||
);
|
||||
const textCenter = pointFrom(
|
||||
x + boundTextElement.width / 2,
|
||||
y + boundTextElement.height / 2,
|
||||
);
|
||||
|
||||
const [rx, ry] = pointRotateRads(textCenter, contentCenter, angle);
|
||||
|
||||
return {
|
||||
x: rx - boundTextElement.width / 2,
|
||||
y: ry - boundTextElement.height / 2,
|
||||
};
|
||||
}
|
||||
|
||||
return { x, y };
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import {
|
||||
DEFAULT_TRANSFORM_HANDLE_SPACING,
|
||||
isAndroid,
|
||||
isIOS,
|
||||
isMobileOrTablet,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { pointFrom, pointRotateRads } from "@excalidraw/math";
|
||||
@@ -327,7 +326,7 @@ export const getTransformHandles = (
|
||||
);
|
||||
};
|
||||
|
||||
export const hasBoundingBox = (
|
||||
export const shouldShowBoundingBox = (
|
||||
elements: readonly NonDeletedExcalidrawElement[],
|
||||
appState: InteractiveCanvasAppState,
|
||||
) => {
|
||||
@@ -346,7 +345,5 @@ export const hasBoundingBox = (
|
||||
return true;
|
||||
}
|
||||
|
||||
// on mobile/tablet we currently don't show bbox because of resize issues
|
||||
// (also prob best for simplicity's sake)
|
||||
return element.points.length > 2 && !isMobileOrTablet();
|
||||
return element.points.length > 2;
|
||||
};
|
||||
|
||||
@@ -380,11 +380,6 @@ export type ExcalidrawFreeDrawElement = _ExcalidrawElementBase &
|
||||
pressures: readonly number[];
|
||||
simulatePressure: boolean;
|
||||
lastCommittedPoint: LocalPoint | null;
|
||||
freedrawOptions: {
|
||||
streamline?: number;
|
||||
simplify?: number;
|
||||
fixedStrokeWidth?: boolean;
|
||||
} | null;
|
||||
}>;
|
||||
|
||||
export type FileId = string & { _brand: "FileId" };
|
||||
|
||||
@@ -10,8 +10,6 @@ import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
||||
import { UI, Pointer, Keyboard } from "@excalidraw/excalidraw/tests/helpers/ui";
|
||||
import { fireEvent, render } from "@excalidraw/excalidraw/tests/test-utils";
|
||||
|
||||
import { LinearElementEditor } from "@excalidraw/element";
|
||||
|
||||
import { getTransformHandles } from "../src/transformHandles";
|
||||
import {
|
||||
getTextEditor,
|
||||
@@ -415,12 +413,16 @@ describe("element binding", () => {
|
||||
expect(arrow.endBinding?.elementId).toBe(rectRight.id);
|
||||
|
||||
// Drag arrow off of bound rectangle range
|
||||
const [elX, elY] = LinearElementEditor.getPointAtIndexGlobalCoordinates(
|
||||
const handles = getTransformHandles(
|
||||
arrow,
|
||||
-1,
|
||||
h.scene.getNonDeletedElementsMap(),
|
||||
);
|
||||
h.state.zoom,
|
||||
arrayToMap(h.elements),
|
||||
"mouse",
|
||||
).se!;
|
||||
|
||||
Keyboard.keyDown(KEYS.CTRL_OR_CMD);
|
||||
const elX = handles[0] + handles[2] / 2;
|
||||
const elY = handles[1] + handles[3] / 2;
|
||||
mouse.downAt(elX, elY);
|
||||
mouse.moveTo(300, 400);
|
||||
mouse.up();
|
||||
|
||||
@@ -8,7 +8,7 @@ import { AppStateDelta, Delta, ElementsDelta } from "../src/delta";
|
||||
|
||||
describe("ElementsDelta", () => {
|
||||
describe("elements delta calculation", () => {
|
||||
it("should not throw when element gets removed but was already deleted", () => {
|
||||
it("should not create removed delta when element gets removed but was already deleted", () => {
|
||||
const element = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 100,
|
||||
@@ -19,12 +19,12 @@ describe("ElementsDelta", () => {
|
||||
const prevElements = new Map([[element.id, element]]);
|
||||
const nextElements = new Map();
|
||||
|
||||
expect(() =>
|
||||
ElementsDelta.calculate(prevElements, nextElements),
|
||||
).not.toThrow();
|
||||
const delta = ElementsDelta.calculate(prevElements, nextElements);
|
||||
|
||||
expect(delta.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should not throw when adding element as already deleted", () => {
|
||||
it("should not create added delta when adding element as already deleted", () => {
|
||||
const element = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 100,
|
||||
@@ -35,12 +35,12 @@ describe("ElementsDelta", () => {
|
||||
const prevElements = new Map();
|
||||
const nextElements = new Map([[element.id, element]]);
|
||||
|
||||
expect(() =>
|
||||
ElementsDelta.calculate(prevElements, nextElements),
|
||||
).not.toThrow();
|
||||
const delta = ElementsDelta.calculate(prevElements, nextElements);
|
||||
|
||||
expect(delta.isEmpty()).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should create updated delta even when there is only version and versionNonce change", () => {
|
||||
it("should not create updated delta when there is only version and versionNonce change", () => {
|
||||
const baseElement = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 100,
|
||||
@@ -65,24 +65,7 @@ describe("ElementsDelta", () => {
|
||||
nextElements as SceneElementsMap,
|
||||
);
|
||||
|
||||
expect(delta).toEqual(
|
||||
ElementsDelta.create(
|
||||
{},
|
||||
{},
|
||||
{
|
||||
[baseElement.id]: Delta.create(
|
||||
{
|
||||
version: baseElement.version,
|
||||
versionNonce: baseElement.versionNonce,
|
||||
},
|
||||
{
|
||||
version: baseElement.version + 1,
|
||||
versionNonce: baseElement.versionNonce + 1,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
expect(delta.isEmpty()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { getLineHeight } from "@excalidraw/common";
|
||||
import { API } from "@excalidraw/excalidraw/tests/helpers/api";
|
||||
|
||||
import { FONT_FAMILY, TEXT_ALIGN, VERTICAL_ALIGN } from "@excalidraw/common";
|
||||
import { FONT_FAMILY } from "@excalidraw/common";
|
||||
|
||||
import {
|
||||
computeContainerDimensionForBoundText,
|
||||
getContainerCoords,
|
||||
getBoundTextMaxWidth,
|
||||
getBoundTextMaxHeight,
|
||||
computeBoundTextPosition,
|
||||
} from "../src/textElement";
|
||||
import { detectLineHeight, getLineHeightInPx } from "../src/textMeasurements";
|
||||
|
||||
@@ -208,172 +207,3 @@ describe("Test getDefaultLineHeight", () => {
|
||||
expect(getLineHeight(FONT_FAMILY.Cascadia)).toBe(1.2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Test computeBoundTextPosition", () => {
|
||||
const createMockElementsMap = () => new Map();
|
||||
|
||||
// Helper function to create rectangle test case with 90-degree rotation
|
||||
const createRotatedRectangleTestCase = (
|
||||
textAlign: string,
|
||||
verticalAlign: string,
|
||||
) => {
|
||||
const container = API.createElement({
|
||||
type: "rectangle",
|
||||
x: 100,
|
||||
y: 100,
|
||||
width: 200,
|
||||
height: 100,
|
||||
angle: (Math.PI / 2) as any, // 90 degrees
|
||||
});
|
||||
|
||||
const boundTextElement = API.createElement({
|
||||
type: "text",
|
||||
width: 80,
|
||||
height: 40,
|
||||
text: "hello darkness my old friend",
|
||||
textAlign: textAlign as any,
|
||||
verticalAlign: verticalAlign as any,
|
||||
containerId: container.id,
|
||||
}) as ExcalidrawTextElementWithContainer;
|
||||
|
||||
const elementsMap = createMockElementsMap();
|
||||
|
||||
return { container, boundTextElement, elementsMap };
|
||||
};
|
||||
|
||||
describe("90-degree rotation with all alignment combinations", () => {
|
||||
// Test all 9 combinations of horizontal (left, center, right) and vertical (top, middle, bottom) alignment
|
||||
|
||||
it("should position text with LEFT + TOP alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.LEFT, VERTICAL_ALIGN.TOP);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(185, 1);
|
||||
expect(result.y).toBeCloseTo(75, 1);
|
||||
});
|
||||
|
||||
it("should position text with LEFT + MIDDLE alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.LEFT, VERTICAL_ALIGN.MIDDLE);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(160, 1);
|
||||
expect(result.y).toBeCloseTo(75, 1);
|
||||
});
|
||||
|
||||
it("should position text with LEFT + BOTTOM alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.LEFT, VERTICAL_ALIGN.BOTTOM);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(135, 1);
|
||||
expect(result.y).toBeCloseTo(75, 1);
|
||||
});
|
||||
|
||||
it("should position text with CENTER + TOP alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.CENTER, VERTICAL_ALIGN.TOP);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(185, 1);
|
||||
expect(result.y).toBeCloseTo(130, 1);
|
||||
});
|
||||
|
||||
it("should position text with CENTER + MIDDLE alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(
|
||||
TEXT_ALIGN.CENTER,
|
||||
VERTICAL_ALIGN.MIDDLE,
|
||||
);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(160, 1);
|
||||
expect(result.y).toBeCloseTo(130, 1);
|
||||
});
|
||||
|
||||
it("should position text with CENTER + BOTTOM alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(
|
||||
TEXT_ALIGN.CENTER,
|
||||
VERTICAL_ALIGN.BOTTOM,
|
||||
);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(135, 1);
|
||||
expect(result.y).toBeCloseTo(130, 1);
|
||||
});
|
||||
|
||||
it("should position text with RIGHT + TOP alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.RIGHT, VERTICAL_ALIGN.TOP);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(185, 1);
|
||||
expect(result.y).toBeCloseTo(185, 1);
|
||||
});
|
||||
|
||||
it("should position text with RIGHT + MIDDLE alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.RIGHT, VERTICAL_ALIGN.MIDDLE);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(160, 1);
|
||||
expect(result.y).toBeCloseTo(185, 1);
|
||||
});
|
||||
|
||||
it("should position text with RIGHT + BOTTOM alignment at 90-degree rotation", () => {
|
||||
const { container, boundTextElement, elementsMap } =
|
||||
createRotatedRectangleTestCase(TEXT_ALIGN.RIGHT, VERTICAL_ALIGN.BOTTOM);
|
||||
|
||||
const result = computeBoundTextPosition(
|
||||
container,
|
||||
boundTextElement,
|
||||
elementsMap,
|
||||
);
|
||||
|
||||
expect(result.x).toBeCloseTo(135, 1);
|
||||
expect(result.y).toBeCloseTo(185, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { isFrameLikeElement } from "@excalidraw/element";
|
||||
|
||||
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
|
||||
|
||||
import { KEYS, arrayToMap } from "@excalidraw/common";
|
||||
import { KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import { alignElements } from "@excalidraw/element";
|
||||
|
||||
@@ -30,8 +30,6 @@ import { t } from "../i18n";
|
||||
|
||||
import { isSomeElementSelected } from "../scene";
|
||||
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
import type { AppClassProperties, AppState, UIAppState } from "../types";
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
} from "@excalidraw/common";
|
||||
import {
|
||||
getOriginalContainerHeightFromCache,
|
||||
isBoundToContainer,
|
||||
resetOriginalContainerCache,
|
||||
updateOriginalContainerCache,
|
||||
} from "@excalidraw/element";
|
||||
@@ -226,9 +225,7 @@ export const actionWrapTextInContainer = register({
|
||||
trackEvent: { category: "element" },
|
||||
predicate: (elements, appState, _, app) => {
|
||||
const selectedElements = app.scene.getSelectedElements(appState);
|
||||
const someTextElements = selectedElements.some(
|
||||
(el) => isTextElement(el) && !isBoundToContainer(el),
|
||||
);
|
||||
const someTextElements = selectedElements.some((el) => isTextElement(el));
|
||||
return selectedElements.length > 0 && someTextElements;
|
||||
},
|
||||
perform: (elements, appState, _, app) => {
|
||||
@@ -237,7 +234,7 @@ export const actionWrapTextInContainer = register({
|
||||
const containerIds: Mutable<AppState["selectedElementIds"]> = {};
|
||||
|
||||
for (const textElement of selectedElements) {
|
||||
if (isTextElement(textElement) && !isBoundToContainer(textElement)) {
|
||||
if (isTextElement(textElement)) {
|
||||
const container = newElement({
|
||||
type: "rectangle",
|
||||
backgroundColor: appState.currentItemBackgroundColor,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
MIN_ZOOM,
|
||||
THEME,
|
||||
ZOOM_STEP,
|
||||
getShortcutKey,
|
||||
updateActiveTool,
|
||||
CODES,
|
||||
KEYS,
|
||||
@@ -45,7 +46,6 @@ import { t } from "../i18n";
|
||||
import { getNormalizedZoom } from "../scene";
|
||||
import { centerScrollOn } from "../scene/scroll";
|
||||
import { getStateForZoom } from "../scene/zoom";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
@@ -69,7 +69,7 @@ export const actionChangeViewBackgroundColor = register({
|
||||
: CaptureUpdateAction.EVENTUALLY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, appProps, data }) => {
|
||||
PanelComponent: ({ elements, appState, updateData, appProps }) => {
|
||||
// FIXME move me to src/components/mainMenu/DefaultItems.tsx
|
||||
return (
|
||||
<ColorPicker
|
||||
@@ -83,7 +83,6 @@ export const actionChangeViewBackgroundColor = register({
|
||||
elements={elements}
|
||||
appState={appState}
|
||||
updateData={updateData}
|
||||
compactMode={appState.stylesPanelMode === "compact"}
|
||||
/>
|
||||
);
|
||||
},
|
||||
@@ -122,10 +121,7 @@ export const actionClearCanvas = register({
|
||||
pasteDialog: appState.pasteDialog,
|
||||
activeTool:
|
||||
appState.activeTool.type === "image"
|
||||
? {
|
||||
...appState.activeTool,
|
||||
type: app.state.preferredSelectionTool.type,
|
||||
}
|
||||
? { ...appState.activeTool, type: app.defaultSelectionTool }
|
||||
: appState.activeTool,
|
||||
},
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
@@ -504,7 +500,7 @@ export const actionToggleEraserTool = register({
|
||||
if (isEraserActive(appState)) {
|
||||
activeTool = updateActiveTool(appState, {
|
||||
...(appState.activeTool.lastActiveTool || {
|
||||
type: app.state.preferredSelectionTool.type,
|
||||
type: app.defaultSelectionTool,
|
||||
}),
|
||||
lastActiveToolBeforeEraser: null,
|
||||
});
|
||||
@@ -535,7 +531,7 @@ export const actionToggleLassoTool = register({
|
||||
icon: LassoIcon,
|
||||
trackEvent: { category: "toolbar" },
|
||||
predicate: (elements, appState, props, app) => {
|
||||
return app.state.preferredSelectionTool.type !== "lasso";
|
||||
return app.defaultSelectionTool !== "lasso";
|
||||
},
|
||||
perform: (elements, appState, _, app) => {
|
||||
let activeTool: AppState["activeTool"];
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
KEYS,
|
||||
MOBILE_ACTION_BUTTON_BG,
|
||||
updateActiveTool,
|
||||
} from "@excalidraw/common";
|
||||
import { KEYS, updateActiveTool } from "@excalidraw/common";
|
||||
|
||||
import { getNonDeletedElements } from "@excalidraw/element";
|
||||
import { fixBindingsAfterDeletion } from "@excalidraw/element";
|
||||
@@ -303,7 +299,7 @@ export const actionDeleteSelected = register({
|
||||
appState: {
|
||||
...nextAppState,
|
||||
activeTool: updateActiveTool(appState, {
|
||||
type: app.state.preferredSelectionTool.type,
|
||||
type: app.defaultSelectionTool,
|
||||
}),
|
||||
multiElement: null,
|
||||
activeEmbeddable: null,
|
||||
@@ -327,15 +323,7 @@ export const actionDeleteSelected = register({
|
||||
title={t("labels.delete")}
|
||||
aria-label={t("labels.delete")}
|
||||
onClick={() => updateData(null)}
|
||||
disabled={
|
||||
!isSomeElementSelected(getNonDeletedElements(elements), appState)
|
||||
}
|
||||
style={{
|
||||
...(appState.stylesPanelMode === "mobile" &&
|
||||
appState.openPopup !== "compactOtherProperties"
|
||||
? MOBILE_ACTION_BUTTON_BG
|
||||
: {}),
|
||||
}}
|
||||
visible={isSomeElementSelected(getNonDeletedElements(elements), appState)}
|
||||
/>
|
||||
),
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { getNonDeletedElements } from "@excalidraw/element";
|
||||
|
||||
import { isFrameLikeElement } from "@excalidraw/element";
|
||||
|
||||
import { CODES, KEYS, arrayToMap } from "@excalidraw/common";
|
||||
import { CODES, KEYS, arrayToMap, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import { updateFrameMembershipOfSelectedElements } from "@excalidraw/element";
|
||||
|
||||
@@ -26,8 +26,6 @@ import { t } from "../i18n";
|
||||
|
||||
import { isSomeElementSelected } from "../scene";
|
||||
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
import type { AppClassProperties, AppState } from "../types";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
DEFAULT_GRID_SIZE,
|
||||
KEYS,
|
||||
MOBILE_ACTION_BUTTON_BG,
|
||||
arrayToMap,
|
||||
getShortcutKey,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { getNonDeletedElements } from "@excalidraw/element";
|
||||
@@ -25,7 +25,6 @@ import { DuplicateIcon } from "../components/icons";
|
||||
|
||||
import { t } from "../i18n";
|
||||
import { isSomeElementSelected } from "../scene";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
@@ -116,15 +115,7 @@ export const actionDuplicateSelection = register({
|
||||
)}`}
|
||||
aria-label={t("labels.duplicateSelection")}
|
||||
onClick={() => updateData(null)}
|
||||
disabled={
|
||||
!isSomeElementSelected(getNonDeletedElements(elements), appState)
|
||||
}
|
||||
style={{
|
||||
...(appState.stylesPanelMode === "mobile" &&
|
||||
appState.openPopup !== "compactOtherProperties"
|
||||
? MOBILE_ACTION_BUTTON_BG
|
||||
: {}),
|
||||
}}
|
||||
visible={isSomeElementSelected(getNonDeletedElements(elements), appState)}
|
||||
/>
|
||||
),
|
||||
});
|
||||
|
||||
@@ -261,13 +261,13 @@ export const actionFinalize = register({
|
||||
if (appState.activeTool.type === "eraser") {
|
||||
activeTool = updateActiveTool(appState, {
|
||||
...(appState.activeTool.lastActiveTool || {
|
||||
type: app.state.preferredSelectionTool.type,
|
||||
type: app.defaultSelectionTool,
|
||||
}),
|
||||
lastActiveToolBeforeEraser: null,
|
||||
});
|
||||
} else {
|
||||
activeTool = updateActiveTool(appState, {
|
||||
type: app.state.preferredSelectionTool.type,
|
||||
type: app.defaultSelectionTool,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
replaceAllElementsInFrame,
|
||||
} from "@excalidraw/element";
|
||||
|
||||
import { KEYS, randomId, arrayToMap } from "@excalidraw/common";
|
||||
import { KEYS, randomId, arrayToMap, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import {
|
||||
getSelectedGroupIds,
|
||||
@@ -43,8 +43,6 @@ import { t } from "../i18n";
|
||||
|
||||
import { isSomeElementSelected } from "../scene";
|
||||
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
import type { AppClassProperties, AppState } from "../types";
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
isWindows,
|
||||
KEYS,
|
||||
matchKey,
|
||||
arrayToMap,
|
||||
MOBILE_ACTION_BUTTON_BG,
|
||||
} from "@excalidraw/common";
|
||||
import { isWindows, KEYS, matchKey, arrayToMap } from "@excalidraw/common";
|
||||
|
||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||
|
||||
@@ -73,7 +67,7 @@ export const createUndoAction: ActionCreator = (history) => ({
|
||||
),
|
||||
keyTest: (event) =>
|
||||
event[KEYS.CTRL_OR_CMD] && matchKey(event, KEYS.Z) && !event.shiftKey,
|
||||
PanelComponent: ({ appState, updateData, data }) => {
|
||||
PanelComponent: ({ updateData, data }) => {
|
||||
const { isUndoStackEmpty } = useEmitter<HistoryChangedEvent>(
|
||||
history.onHistoryChangedEmitter,
|
||||
new HistoryChangedEvent(
|
||||
@@ -91,11 +85,6 @@ export const createUndoAction: ActionCreator = (history) => ({
|
||||
size={data?.size || "medium"}
|
||||
disabled={isUndoStackEmpty}
|
||||
data-testid="button-undo"
|
||||
style={{
|
||||
...(appState.stylesPanelMode === "mobile"
|
||||
? MOBILE_ACTION_BUTTON_BG
|
||||
: {}),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
@@ -114,7 +103,7 @@ export const createRedoAction: ActionCreator = (history) => ({
|
||||
keyTest: (event) =>
|
||||
(event[KEYS.CTRL_OR_CMD] && event.shiftKey && matchKey(event, KEYS.Z)) ||
|
||||
(isWindows && event.ctrlKey && !event.shiftKey && matchKey(event, KEYS.Y)),
|
||||
PanelComponent: ({ appState, updateData, data }) => {
|
||||
PanelComponent: ({ updateData, data }) => {
|
||||
const { isRedoStackEmpty } = useEmitter(
|
||||
history.onHistoryChangedEmitter,
|
||||
new HistoryChangedEvent(
|
||||
@@ -132,11 +121,6 @@ export const createRedoAction: ActionCreator = (history) => ({
|
||||
size={data?.size || "medium"}
|
||||
disabled={isRedoStackEmpty}
|
||||
data-testid="button-redo"
|
||||
style={{
|
||||
...(appState.stylesPanelMode === "mobile"
|
||||
? MOBILE_ACTION_BUTTON_BG
|
||||
: {}),
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
|
||||
@@ -88,10 +88,6 @@ export const actionToggleLinearEditor = register({
|
||||
selectedElementIds: appState.selectedElementIds,
|
||||
})[0] as ExcalidrawLinearElement;
|
||||
|
||||
if (!selectedElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const label = t(
|
||||
selectedElement.type === "arrow"
|
||||
? "labels.lineEditor.editArrow"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isEmbeddableElement } from "@excalidraw/element";
|
||||
|
||||
import { KEYS } from "@excalidraw/common";
|
||||
import { KEYS, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||
|
||||
@@ -8,8 +8,8 @@ import { ToolButton } from "../components/ToolButton";
|
||||
import { getContextMenuLabel } from "../components/hyperlink/Hyperlink";
|
||||
import { LinkIcon } from "../components/icons";
|
||||
import { t } from "../i18n";
|
||||
|
||||
import { getSelectedElements } from "../scene";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
|
||||
@@ -1,11 +1,65 @@
|
||||
import { KEYS } from "@excalidraw/common";
|
||||
|
||||
import { getNonDeletedElements } from "@excalidraw/element";
|
||||
|
||||
import { showSelectedShapeActions } from "@excalidraw/element";
|
||||
|
||||
import { CaptureUpdateAction } from "@excalidraw/element";
|
||||
|
||||
import { HelpIconThin } from "../components/icons";
|
||||
import { ToolButton } from "../components/ToolButton";
|
||||
import { HamburgerMenuIcon, HelpIconThin, palette } from "../components/icons";
|
||||
import { t } from "../i18n";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
export const actionToggleCanvasMenu = register({
|
||||
name: "toggleCanvasMenu",
|
||||
label: "buttons.menu",
|
||||
trackEvent: { category: "menu" },
|
||||
perform: (_, appState) => ({
|
||||
appState: {
|
||||
...appState,
|
||||
openMenu: appState.openMenu === "canvas" ? null : "canvas",
|
||||
},
|
||||
captureUpdate: CaptureUpdateAction.EVENTUALLY,
|
||||
}),
|
||||
PanelComponent: ({ appState, updateData }) => (
|
||||
<ToolButton
|
||||
type="button"
|
||||
icon={HamburgerMenuIcon}
|
||||
aria-label={t("buttons.menu")}
|
||||
onClick={updateData}
|
||||
selected={appState.openMenu === "canvas"}
|
||||
/>
|
||||
),
|
||||
});
|
||||
|
||||
export const actionToggleEditMenu = register({
|
||||
name: "toggleEditMenu",
|
||||
label: "buttons.edit",
|
||||
trackEvent: { category: "menu" },
|
||||
perform: (_elements, appState) => ({
|
||||
appState: {
|
||||
...appState,
|
||||
openMenu: appState.openMenu === "shape" ? null : "shape",
|
||||
},
|
||||
captureUpdate: CaptureUpdateAction.EVENTUALLY,
|
||||
}),
|
||||
PanelComponent: ({ elements, appState, updateData }) => (
|
||||
<ToolButton
|
||||
visible={showSelectedShapeActions(
|
||||
appState,
|
||||
getNonDeletedElements(elements),
|
||||
)}
|
||||
type="button"
|
||||
icon={palette}
|
||||
aria-label={t("buttons.edit")}
|
||||
onClick={updateData}
|
||||
selected={appState.openMenu === "shape"}
|
||||
/>
|
||||
),
|
||||
});
|
||||
|
||||
export const actionShortcuts = register({
|
||||
name: "toggleShortcuts",
|
||||
label: "welcomeScreen.defaults.helpHint",
|
||||
@@ -25,8 +79,6 @@ export const actionShortcuts = register({
|
||||
: {
|
||||
name: "help",
|
||||
},
|
||||
openMenu: null,
|
||||
openPopup: null,
|
||||
},
|
||||
captureUpdate: CaptureUpdateAction.EVENTUALLY,
|
||||
};
|
||||
|
||||
@@ -145,27 +145,26 @@ describe("element locking", () => {
|
||||
queryByTestId(document.body, `strokeWidth-thin`),
|
||||
).not.toBeChecked();
|
||||
expect(
|
||||
queryByTestId(document.body, `strokeWidth-medium`),
|
||||
queryByTestId(document.body, `strokeWidth-bold`),
|
||||
).not.toBeChecked();
|
||||
expect(
|
||||
queryByTestId(document.body, `strokeWidth-bold`),
|
||||
queryByTestId(document.body, `strokeWidth-extraBold`),
|
||||
).not.toBeChecked();
|
||||
});
|
||||
|
||||
it("should show properties of different element types when selected", () => {
|
||||
const rect = API.createElement({
|
||||
type: "rectangle",
|
||||
strokeWidth: STROKE_WIDTH.medium,
|
||||
strokeWidth: STROKE_WIDTH.bold,
|
||||
});
|
||||
const text = API.createElement({
|
||||
type: "text",
|
||||
fontFamily: FONT_FAMILY["Comic Shanns"],
|
||||
strokeWidth: undefined,
|
||||
});
|
||||
API.setElements([rect, text]);
|
||||
API.setSelectedElements([rect, text]);
|
||||
|
||||
expect(queryByTestId(document.body, `strokeWidth-medium`)).toBeChecked();
|
||||
expect(queryByTestId(document.body, `strokeWidth-bold`)).toBeChecked();
|
||||
expect(queryByTestId(document.body, `font-family-code`)).toHaveClass(
|
||||
"active",
|
||||
);
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
randomInteger,
|
||||
arrayToMap,
|
||||
getFontFamilyString,
|
||||
getShortcutKey,
|
||||
getLineHeight,
|
||||
isTransparent,
|
||||
reduceToCommonValue,
|
||||
@@ -43,7 +44,6 @@ import {
|
||||
isArrowElement,
|
||||
isBoundToContainer,
|
||||
isElbowArrow,
|
||||
isFreeDrawElement,
|
||||
isLinearElement,
|
||||
isLineElement,
|
||||
isTextElement,
|
||||
@@ -126,9 +126,6 @@ import {
|
||||
ArrowheadCrowfootIcon,
|
||||
ArrowheadCrowfootOneIcon,
|
||||
ArrowheadCrowfootOneOrManyIcon,
|
||||
strokeWidthFixedIcon,
|
||||
strokeWidthVariableIcon,
|
||||
StrokeWidthMediumIcon,
|
||||
} from "../components/icons";
|
||||
|
||||
import { Fonts } from "../fonts";
|
||||
@@ -140,13 +137,6 @@ import {
|
||||
isSomeElementSelected,
|
||||
} from "../scene";
|
||||
|
||||
import {
|
||||
withCaretPositionPreservation,
|
||||
restoreCaretPosition,
|
||||
} from "../hooks/useTextEditorFocus";
|
||||
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
import type { AppClassProperties, AppState, Primitive } from "../types";
|
||||
@@ -331,11 +321,9 @@ export const actionChangeStrokeColor = register({
|
||||
: CaptureUpdateAction.EVENTUALLY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
||||
<>
|
||||
{appState.stylesPanelMode === "full" && (
|
||||
<h3 aria-hidden="true">{t("labels.stroke")}</h3>
|
||||
)}
|
||||
<h3 aria-hidden="true">{t("labels.stroke")}</h3>
|
||||
<ColorPicker
|
||||
topPicks={DEFAULT_ELEMENT_STROKE_PICKS}
|
||||
palette={DEFAULT_ELEMENT_STROKE_COLOR_PALETTE}
|
||||
@@ -353,10 +341,6 @@ export const actionChangeStrokeColor = register({
|
||||
elements={elements}
|
||||
appState={appState}
|
||||
updateData={updateData}
|
||||
compactMode={
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile"
|
||||
}
|
||||
/>
|
||||
</>
|
||||
),
|
||||
@@ -414,11 +398,9 @@ export const actionChangeBackgroundColor = register({
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
||||
<>
|
||||
{appState.stylesPanelMode === "full" && (
|
||||
<h3 aria-hidden="true">{t("labels.background")}</h3>
|
||||
)}
|
||||
<h3 aria-hidden="true">{t("labels.background")}</h3>
|
||||
<ColorPicker
|
||||
topPicks={DEFAULT_ELEMENT_BACKGROUND_PICKS}
|
||||
palette={DEFAULT_ELEMENT_BACKGROUND_COLOR_PALETTE}
|
||||
@@ -436,10 +418,6 @@ export const actionChangeBackgroundColor = register({
|
||||
elements={elements}
|
||||
appState={appState}
|
||||
updateData={updateData}
|
||||
compactMode={
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile"
|
||||
}
|
||||
/>
|
||||
</>
|
||||
),
|
||||
@@ -525,33 +503,6 @@ export const actionChangeFillStyle = register({
|
||||
},
|
||||
});
|
||||
|
||||
const WIDTHS = [
|
||||
{
|
||||
value: STROKE_WIDTH.thin,
|
||||
text: t("labels.thin"),
|
||||
icon: StrokeWidthBaseIcon,
|
||||
testId: "strokeWidth-thin",
|
||||
},
|
||||
{
|
||||
value: STROKE_WIDTH.medium,
|
||||
text: t("labels.medium"),
|
||||
icon: StrokeWidthMediumIcon,
|
||||
testId: "strokeWidth-medium",
|
||||
},
|
||||
{
|
||||
value: STROKE_WIDTH.bold,
|
||||
text: t("labels.bold"),
|
||||
icon: StrokeWidthBoldIcon,
|
||||
testId: "strokeWidth-bold",
|
||||
},
|
||||
{
|
||||
value: STROKE_WIDTH.extraBold,
|
||||
text: t("labels.extraBold"),
|
||||
icon: StrokeWidthExtraBoldIcon,
|
||||
testId: "strokeWidth-extraBold",
|
||||
},
|
||||
];
|
||||
|
||||
export const actionChangeStrokeWidth = register({
|
||||
name: "changeStrokeWidth",
|
||||
label: "labels.strokeWidth",
|
||||
@@ -567,13 +518,32 @@ export const actionChangeStrokeWidth = register({
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
||||
<fieldset>
|
||||
<legend>{t("labels.strokeWidth")}</legend>
|
||||
<div className="buttonList">
|
||||
<RadioSelection
|
||||
group="stroke-width"
|
||||
options={WIDTHS}
|
||||
options={[
|
||||
{
|
||||
value: STROKE_WIDTH.thin,
|
||||
text: t("labels.thin"),
|
||||
icon: StrokeWidthBaseIcon,
|
||||
testId: "strokeWidth-thin",
|
||||
},
|
||||
{
|
||||
value: STROKE_WIDTH.bold,
|
||||
text: t("labels.bold"),
|
||||
icon: StrokeWidthBoldIcon,
|
||||
testId: "strokeWidth-bold",
|
||||
},
|
||||
{
|
||||
value: STROKE_WIDTH.extraBold,
|
||||
text: t("labels.extraBold"),
|
||||
icon: StrokeWidthExtraBoldIcon,
|
||||
testId: "strokeWidth-extraBold",
|
||||
},
|
||||
]}
|
||||
value={getFormValue(
|
||||
elements,
|
||||
app,
|
||||
@@ -605,7 +575,7 @@ export const actionChangeSloppiness = register({
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
||||
<fieldset>
|
||||
<legend>{t("labels.sloppiness")}</legend>
|
||||
<div className="buttonList">
|
||||
@@ -658,7 +628,7 @@ export const actionChangeStrokeStyle = register({
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
||||
<fieldset>
|
||||
<legend>{t("labels.strokeStyle")}</legend>
|
||||
<div className="buttonList">
|
||||
@@ -696,70 +666,6 @@ export const actionChangeStrokeStyle = register({
|
||||
),
|
||||
});
|
||||
|
||||
export const actionChangePressureSensitivity = register({
|
||||
name: "changeStrokeType",
|
||||
label: "labels.strokeType",
|
||||
trackEvent: false,
|
||||
perform: (elements, appState, value) => {
|
||||
const updatedElements = changeProperty(elements, appState, (el) => {
|
||||
if (isFreeDrawElement(el)) {
|
||||
return newElementWith(el, {
|
||||
freedrawOptions: {
|
||||
...el.freedrawOptions,
|
||||
fixedStrokeWidth: value,
|
||||
},
|
||||
});
|
||||
}
|
||||
return el;
|
||||
});
|
||||
|
||||
return {
|
||||
elements: updatedElements,
|
||||
appState: { ...appState, currentItemFixedStrokeWidth: value },
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ app, appState, updateData }) => {
|
||||
const selectedElements = app.scene.getSelectedElements(app.state);
|
||||
const freedraws = selectedElements.filter(isFreeDrawElement);
|
||||
|
||||
const currentValue =
|
||||
freedraws.length > 0
|
||||
? reduceToCommonValue(
|
||||
freedraws,
|
||||
(element) => element.freedrawOptions?.fixedStrokeWidth,
|
||||
) ?? null
|
||||
: appState.currentItemFixedStrokeWidth;
|
||||
|
||||
return (
|
||||
<fieldset>
|
||||
<legend>{t("labels.strokeType")}</legend>
|
||||
<div className="buttonList">
|
||||
<RadioSelection
|
||||
group="pressure-sensitivity"
|
||||
options={[
|
||||
{
|
||||
value: true,
|
||||
text: t("labels.strokeWidthFixed"),
|
||||
icon: strokeWidthFixedIcon,
|
||||
testId: "pressure-fixed",
|
||||
},
|
||||
{
|
||||
value: false,
|
||||
text: t("labels.strokeWidthVariable"),
|
||||
icon: strokeWidthVariableIcon,
|
||||
testId: "pressure-variable",
|
||||
},
|
||||
]}
|
||||
value={currentValue}
|
||||
onChange={(value) => updateData(value)}
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const actionChangeOpacity = register({
|
||||
name: "changeOpacity",
|
||||
label: "labels.opacity",
|
||||
@@ -791,7 +697,7 @@ export const actionChangeFontSize = register({
|
||||
perform: (elements, appState, value, app) => {
|
||||
return changeFontSize(elements, appState, app, () => value, value);
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => (
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => (
|
||||
<fieldset>
|
||||
<legend>{t("labels.fontSize")}</legend>
|
||||
<div className="buttonList">
|
||||
@@ -850,15 +756,7 @@ export const actionChangeFontSize = register({
|
||||
? null
|
||||
: appState.currentItemFontSize || DEFAULT_FONT_SIZE,
|
||||
)}
|
||||
onChange={(value) => {
|
||||
withCaretPositionPreservation(
|
||||
() => updateData(value),
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile",
|
||||
!!appState.editingTextElement,
|
||||
data?.onPreventClose,
|
||||
);
|
||||
}}
|
||||
onChange={(value) => updateData(value)}
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -1195,30 +1093,21 @@ export const actionChangeFontFamily = register({
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{appState.stylesPanelMode === "full" && (
|
||||
<legend>{t("labels.fontFamily")}</legend>
|
||||
)}
|
||||
<fieldset>
|
||||
<legend>{t("labels.fontFamily")}</legend>
|
||||
<FontPicker
|
||||
isOpened={appState.openPopup === "fontFamily"}
|
||||
selectedFontFamily={selectedFontFamily}
|
||||
hoveredFontFamily={appState.currentHoveredFontFamily}
|
||||
compactMode={appState.stylesPanelMode !== "full"}
|
||||
onSelect={(fontFamily) => {
|
||||
withCaretPositionPreservation(
|
||||
() => {
|
||||
setBatchedData({
|
||||
openPopup: null,
|
||||
currentHoveredFontFamily: null,
|
||||
currentItemFontFamily: fontFamily,
|
||||
});
|
||||
// defensive clear so immediate close won't abuse the cached elements
|
||||
cachedElementsRef.current.clear();
|
||||
},
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile",
|
||||
!!appState.editingTextElement,
|
||||
);
|
||||
setBatchedData({
|
||||
openPopup: null,
|
||||
currentHoveredFontFamily: null,
|
||||
currentItemFontFamily: fontFamily,
|
||||
});
|
||||
|
||||
// defensive clear so immediate close won't abuse the cached elements
|
||||
cachedElementsRef.current.clear();
|
||||
}}
|
||||
onHover={(fontFamily) => {
|
||||
setBatchedData({
|
||||
@@ -1275,33 +1164,29 @@ export const actionChangeFontFamily = register({
|
||||
}
|
||||
|
||||
setBatchedData({
|
||||
...batchedData,
|
||||
openPopup: "fontFamily",
|
||||
});
|
||||
} else {
|
||||
const fontFamilyData = {
|
||||
// close, use the cache and clear it afterwards
|
||||
const data = {
|
||||
openPopup: null,
|
||||
currentHoveredFontFamily: null,
|
||||
cachedElements: new Map(cachedElementsRef.current),
|
||||
resetAll: true,
|
||||
} as ChangeFontFamilyData;
|
||||
|
||||
setBatchedData({
|
||||
...fontFamilyData,
|
||||
});
|
||||
cachedElementsRef.current.clear();
|
||||
|
||||
// Refocus text editor when font picker closes if we were editing text
|
||||
if (
|
||||
(appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile") &&
|
||||
appState.editingTextElement
|
||||
) {
|
||||
restoreCaretPosition(null); // Just refocus without saved position
|
||||
if (isUnmounted.current) {
|
||||
// in case the component was unmounted by the parent, trigger the update directly
|
||||
updateData({ ...batchedData, ...data });
|
||||
} else {
|
||||
setBatchedData(data);
|
||||
}
|
||||
|
||||
cachedElementsRef.current.clear();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
</fieldset>
|
||||
);
|
||||
},
|
||||
});
|
||||
@@ -1340,9 +1225,8 @@ export const actionChangeTextAlign = register({
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => {
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => {
|
||||
const elementsMap = app.scene.getNonDeletedElementsMap();
|
||||
|
||||
return (
|
||||
<fieldset>
|
||||
<legend>{t("labels.textAlign")}</legend>
|
||||
@@ -1391,15 +1275,7 @@ export const actionChangeTextAlign = register({
|
||||
(hasSelection) =>
|
||||
hasSelection ? null : appState.currentItemTextAlign,
|
||||
)}
|
||||
onChange={(value) => {
|
||||
withCaretPositionPreservation(
|
||||
() => updateData(value),
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile",
|
||||
!!appState.editingTextElement,
|
||||
data?.onPreventClose,
|
||||
);
|
||||
}}
|
||||
onChange={(value) => updateData(value)}
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -1441,7 +1317,7 @@ export const actionChangeVerticalAlign = register({
|
||||
captureUpdate: CaptureUpdateAction.IMMEDIATELY,
|
||||
};
|
||||
},
|
||||
PanelComponent: ({ elements, appState, updateData, app, data }) => {
|
||||
PanelComponent: ({ elements, appState, updateData, app }) => {
|
||||
return (
|
||||
<fieldset>
|
||||
<div className="buttonList">
|
||||
@@ -1491,15 +1367,7 @@ export const actionChangeVerticalAlign = register({
|
||||
) !== null,
|
||||
(hasSelection) => (hasSelection ? null : VERTICAL_ALIGN.MIDDLE),
|
||||
)}
|
||||
onChange={(value) => {
|
||||
withCaretPositionPreservation(
|
||||
() => updateData(value),
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile",
|
||||
!!appState.editingTextElement,
|
||||
data?.onPreventClose,
|
||||
);
|
||||
}}
|
||||
onChange={(value) => updateData(value)}
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -1748,25 +1616,6 @@ 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("changeArrowhead")}
|
||||
{renderAction("changeArrowType")}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const actionChangeArrowType = register({
|
||||
name: "changeArrowType",
|
||||
label: "Change arrow types",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { KEYS, CODES, isDarwin } from "@excalidraw/common";
|
||||
import { KEYS, CODES, getShortcutKey, isDarwin } from "@excalidraw/common";
|
||||
|
||||
import {
|
||||
moveOneLeft,
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
SendToBackIcon,
|
||||
} from "../components/icons";
|
||||
import { t } from "../i18n";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { register } from "./register";
|
||||
|
||||
|
||||
@@ -13,13 +13,11 @@ export {
|
||||
actionChangeStrokeWidth,
|
||||
actionChangeFillStyle,
|
||||
actionChangeSloppiness,
|
||||
actionChangePressureSensitivity,
|
||||
actionChangeOpacity,
|
||||
actionChangeFontSize,
|
||||
actionChangeFontFamily,
|
||||
actionChangeTextAlign,
|
||||
actionChangeVerticalAlign,
|
||||
actionChangeArrowProperties,
|
||||
} from "./actionProperties";
|
||||
|
||||
export {
|
||||
@@ -45,7 +43,11 @@ export {
|
||||
} from "./actionExport";
|
||||
|
||||
export { actionCopyStyles, actionPasteStyles } from "./actionStyles";
|
||||
export { actionShortcuts } from "./actionMenu";
|
||||
export {
|
||||
actionToggleCanvasMenu,
|
||||
actionToggleEditMenu,
|
||||
actionShortcuts,
|
||||
} from "./actionMenu";
|
||||
|
||||
export { actionGroup, actionUngroup } from "./actionGroup";
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { isDarwin } from "@excalidraw/common";
|
||||
import { isDarwin, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import type { SubtypeOf } from "@excalidraw/common/utility-types";
|
||||
|
||||
import { t } from "../i18n";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import type { ActionName } from "./types";
|
||||
|
||||
|
||||
@@ -69,10 +69,10 @@ export type ActionName =
|
||||
| "changeStrokeStyle"
|
||||
| "changeArrowhead"
|
||||
| "changeArrowType"
|
||||
| "changeStrokeType"
|
||||
| "changeArrowProperties"
|
||||
| "changeOpacity"
|
||||
| "changeFontSize"
|
||||
| "toggleCanvasMenu"
|
||||
| "toggleEditMenu"
|
||||
| "undo"
|
||||
| "redo"
|
||||
| "finalize"
|
||||
|
||||
@@ -34,7 +34,6 @@ export const getDefaultAppState = (): Omit<
|
||||
currentItemFontFamily: DEFAULT_FONT_FAMILY,
|
||||
currentItemFontSize: DEFAULT_FONT_SIZE,
|
||||
currentItemOpacity: DEFAULT_ELEMENT_PROPS.opacity,
|
||||
currentItemFixedStrokeWidth: true,
|
||||
currentItemRoughness: DEFAULT_ELEMENT_PROPS.roughness,
|
||||
currentItemStartArrowhead: null,
|
||||
currentItemStrokeColor: DEFAULT_ELEMENT_PROPS.strokeColor,
|
||||
@@ -56,10 +55,6 @@ export const getDefaultAppState = (): Omit<
|
||||
fromSelection: false,
|
||||
lastActiveTool: null,
|
||||
},
|
||||
preferredSelectionTool: {
|
||||
type: "selection",
|
||||
initialized: false,
|
||||
},
|
||||
penMode: false,
|
||||
penDetected: false,
|
||||
errorMessage: null,
|
||||
@@ -128,7 +123,6 @@ export const getDefaultAppState = (): Omit<
|
||||
searchMatches: null,
|
||||
lockedMultiSelections: {},
|
||||
activeLockedId: null,
|
||||
stylesPanelMode: "full",
|
||||
};
|
||||
};
|
||||
|
||||
@@ -168,11 +162,6 @@ const APP_STATE_STORAGE_CONF = (<
|
||||
server: false,
|
||||
},
|
||||
currentItemOpacity: { browser: true, export: false, server: false },
|
||||
currentItemFixedStrokeWidth: {
|
||||
browser: true,
|
||||
export: false,
|
||||
server: false,
|
||||
},
|
||||
currentItemRoughness: { browser: true, export: false, server: false },
|
||||
currentItemStartArrowhead: { browser: true, export: false, server: false },
|
||||
currentItemStrokeColor: { browser: true, export: false, server: false },
|
||||
@@ -186,7 +175,6 @@ const APP_STATE_STORAGE_CONF = (<
|
||||
editingTextElement: { browser: false, export: false, server: false },
|
||||
editingGroupId: { browser: true, export: false, server: false },
|
||||
activeTool: { browser: true, export: false, server: false },
|
||||
preferredSelectionTool: { browser: true, export: false, server: false },
|
||||
penMode: { browser: true, export: false, server: false },
|
||||
penDetected: { browser: true, export: false, server: false },
|
||||
errorMessage: { browser: false, export: false, server: false },
|
||||
@@ -259,7 +247,6 @@ const APP_STATE_STORAGE_CONF = (<
|
||||
searchMatches: { browser: false, export: false, server: false },
|
||||
lockedMultiSelections: { browser: true, export: true, server: true },
|
||||
activeLockedId: { browser: false, export: false, server: false },
|
||||
stylesPanelMode: { browser: false, export: false, server: false },
|
||||
});
|
||||
|
||||
const _clearAppStateForStorage = <
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
createPasteEvent,
|
||||
parseClipboard,
|
||||
parseDataTransferEvent,
|
||||
serializeAsClipboardJSON,
|
||||
} from "./clipboard";
|
||||
import { API } from "./tests/helpers/api";
|
||||
@@ -14,9 +13,7 @@ describe("parseClipboard()", () => {
|
||||
|
||||
text = "123";
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({ types: { "text/plain": text } }),
|
||||
),
|
||||
createPasteEvent({ types: { "text/plain": text } }),
|
||||
);
|
||||
expect(clipboardData.text).toBe(text);
|
||||
|
||||
@@ -24,9 +21,7 @@ describe("parseClipboard()", () => {
|
||||
|
||||
text = "[123]";
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({ types: { "text/plain": text } }),
|
||||
),
|
||||
createPasteEvent({ types: { "text/plain": text } }),
|
||||
);
|
||||
expect(clipboardData.text).toBe(text);
|
||||
|
||||
@@ -34,9 +29,7 @@ describe("parseClipboard()", () => {
|
||||
|
||||
text = JSON.stringify({ val: 42 });
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({ types: { "text/plain": text } }),
|
||||
),
|
||||
createPasteEvent({ types: { "text/plain": text } }),
|
||||
);
|
||||
expect(clipboardData.text).toBe(text);
|
||||
});
|
||||
@@ -46,13 +39,11 @@ describe("parseClipboard()", () => {
|
||||
|
||||
const json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||
const clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/plain": json,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/plain": json,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.elements).toEqual([rect]);
|
||||
});
|
||||
@@ -65,25 +56,21 @@ describe("parseClipboard()", () => {
|
||||
// -------------------------------------------------------------------------
|
||||
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": json,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": json,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.elements).toEqual([rect]);
|
||||
// -------------------------------------------------------------------------
|
||||
json = serializeAsClipboardJSON({ elements: [rect], files: null });
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<div> ${json}</div>`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<div> ${json}</div>`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.elements).toEqual([rect]);
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -93,13 +80,11 @@ describe("parseClipboard()", () => {
|
||||
let clipboardData;
|
||||
// -------------------------------------------------------------------------
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<img src="https://example.com/image.png" />`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<img src="https://example.com/image.png" />`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.mixedContent).toEqual([
|
||||
{
|
||||
@@ -109,13 +94,11 @@ describe("parseClipboard()", () => {
|
||||
]);
|
||||
// -------------------------------------------------------------------------
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<div><img src="https://example.com/image.png" /></div><a><img src="https://example.com/image2.png" /></a>`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<div><img src="https://example.com/image.png" /></div><a><img src="https://example.com/image2.png" /></a>`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.mixedContent).toEqual([
|
||||
{
|
||||
@@ -131,13 +114,11 @@ describe("parseClipboard()", () => {
|
||||
|
||||
it("should parse text content alongside <image> `src` urls out of text/html", async () => {
|
||||
const clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<a href="https://example.com">hello </a><div><img src="https://example.com/image.png" /></div><b>my friend!</b>`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"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([
|
||||
{
|
||||
@@ -160,16 +141,14 @@ describe("parseClipboard()", () => {
|
||||
let clipboardData;
|
||||
// -------------------------------------------------------------------------
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/plain": `a b
|
||||
1 2
|
||||
4 5
|
||||
7 10`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/plain": `a b
|
||||
1 2
|
||||
4 5
|
||||
7 10`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.spreadsheet).toEqual({
|
||||
title: "b",
|
||||
@@ -178,16 +157,14 @@ describe("parseClipboard()", () => {
|
||||
});
|
||||
// -------------------------------------------------------------------------
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `a b
|
||||
1 2
|
||||
4 5
|
||||
7 10`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `a b
|
||||
1 2
|
||||
4 5
|
||||
7 10`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.spreadsheet).toEqual({
|
||||
title: "b",
|
||||
@@ -196,21 +173,19 @@ describe("parseClipboard()", () => {
|
||||
});
|
||||
// -------------------------------------------------------------------------
|
||||
clipboardData = await parseClipboard(
|
||||
await parseDataTransferEvent(
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<html>
|
||||
<body>
|
||||
<!--StartFragment--><google-sheets-html-origin><style type="text/css"><!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="100"/><col width="100"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"a"}">a</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"b"}">b</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":1}">1</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":2}">2</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":4}">4</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":5}">5</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":7}">7</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":10}">10</td></tr></tbody></table><!--EndFragment-->
|
||||
</body>
|
||||
</html>`,
|
||||
"text/plain": `a b
|
||||
1 2
|
||||
4 5
|
||||
7 10`,
|
||||
},
|
||||
}),
|
||||
),
|
||||
createPasteEvent({
|
||||
types: {
|
||||
"text/html": `<html>
|
||||
<body>
|
||||
<!--StartFragment--><google-sheets-html-origin><style type="text/css"><!--td {border: 1px solid #cccccc;}br {mso-data-placement:same-cell;}--></style><table xmlns="http://www.w3.org/1999/xhtml" cellspacing="0" cellpadding="0" dir="ltr" border="1" style="table-layout:fixed;font-size:10pt;font-family:Arial;width:0px;border-collapse:collapse;border:none"><colgroup><col width="100"/><col width="100"/></colgroup><tbody><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"a"}">a</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;" data-sheets-value="{"1":2,"2":"b"}">b</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":1}">1</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":2}">2</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":4}">4</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":5}">5</td></tr><tr style="height:21px;"><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":7}">7</td><td style="overflow:hidden;padding:2px 3px 2px 3px;vertical-align:bottom;text-align:right;" data-sheets-value="{"1":3,"3":10}">10</td></tr></tbody></table><!--EndFragment-->
|
||||
</body>
|
||||
</html>`,
|
||||
"text/plain": `a b
|
||||
1 2
|
||||
4 5
|
||||
7 10`,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(clipboardData.spreadsheet).toEqual({
|
||||
title: "b",
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
arrayToMap,
|
||||
isMemberOf,
|
||||
isPromiseLike,
|
||||
EVENT,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { mutateElement } from "@excalidraw/element";
|
||||
@@ -17,26 +16,15 @@ import {
|
||||
|
||||
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 {
|
||||
ExcalidrawElement,
|
||||
NonDeletedExcalidrawElement,
|
||||
} from "@excalidraw/element/types";
|
||||
|
||||
import { ExcalidrawError } from "./errors";
|
||||
import {
|
||||
createFile,
|
||||
getFileHandle,
|
||||
isSupportedImageFileType,
|
||||
normalizeFile,
|
||||
} from "./data/blob";
|
||||
|
||||
import { createFile, isSupportedImageFileType } from "./data/blob";
|
||||
import { tryParseSpreadsheet, VALID_SPREADSHEET } from "./charts";
|
||||
|
||||
import type { FileSystemHandle } from "./data/filesystem";
|
||||
|
||||
import type { Spreadsheet } from "./charts";
|
||||
|
||||
import type { BinaryFiles } from "./types";
|
||||
@@ -104,7 +92,7 @@ export const createPasteEvent = ({
|
||||
console.warn("createPasteEvent: no types or files provided");
|
||||
}
|
||||
|
||||
const event = new ClipboardEvent(EVENT.PASTE, {
|
||||
const event = new ClipboardEvent("paste", {
|
||||
clipboardData: new DataTransfer(),
|
||||
});
|
||||
|
||||
@@ -113,11 +101,10 @@ export const createPasteEvent = ({
|
||||
if (typeof value !== "string") {
|
||||
files = files || [];
|
||||
files.push(value);
|
||||
event.clipboardData?.items.add(value);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
event.clipboardData?.items.add(value, type);
|
||||
event.clipboardData?.setData(type, value);
|
||||
if (event.clipboardData?.getData(type) !== value) {
|
||||
throw new Error(`Failed to set "${type}" as clipboardData item`);
|
||||
}
|
||||
@@ -242,10 +229,14 @@ function parseHTMLTree(el: ChildNode) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const maybeParseHTMLDataItem = (
|
||||
dataItem: ParsedDataTransferItemType<typeof MIME_TYPES["html"]>,
|
||||
const maybeParseHTMLPaste = (
|
||||
event: ClipboardEvent,
|
||||
): { type: "mixedContent"; value: PastedMixedContent } | null => {
|
||||
const html = dataItem.value;
|
||||
const html = event.clipboardData?.getData(MIME_TYPES.html);
|
||||
|
||||
if (!html) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const doc = new DOMParser().parseFromString(html, MIME_TYPES.html);
|
||||
@@ -341,21 +332,18 @@ export const readSystemClipboard = async () => {
|
||||
* Parses "paste" ClipboardEvent.
|
||||
*/
|
||||
const parseClipboardEventTextData = async (
|
||||
dataList: ParsedDataTranferList,
|
||||
event: ClipboardEvent,
|
||||
isPlainPaste = false,
|
||||
): Promise<ParsedClipboardEventTextData> => {
|
||||
try {
|
||||
const htmlItem = dataList.findByType(MIME_TYPES.html);
|
||||
|
||||
const mixedContent =
|
||||
!isPlainPaste && htmlItem && maybeParseHTMLDataItem(htmlItem);
|
||||
const mixedContent = !isPlainPaste && event && maybeParseHTMLPaste(event);
|
||||
|
||||
if (mixedContent) {
|
||||
if (mixedContent.value.every((item) => item.type === "text")) {
|
||||
return {
|
||||
type: "text",
|
||||
value:
|
||||
dataList.getData(MIME_TYPES.text) ??
|
||||
event.clipboardData?.getData(MIME_TYPES.text) ||
|
||||
mixedContent.value
|
||||
.map((item) => item.value)
|
||||
.join("\n")
|
||||
@@ -366,156 +354,23 @@ const parseClipboardEventTextData = async (
|
||||
return mixedContent;
|
||||
}
|
||||
|
||||
return {
|
||||
type: "text",
|
||||
value: (dataList.getData(MIME_TYPES.text) || "").trim(),
|
||||
};
|
||||
const text = event.clipboardData?.getData(MIME_TYPES.text);
|
||||
|
||||
return { type: "text", value: (text || "").trim() };
|
||||
} catch {
|
||||
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") {
|
||||
let file = item.getAsFile();
|
||||
if (file) {
|
||||
const fileHandle = await getFileHandle(item);
|
||||
file = await normalizeFile(file);
|
||||
return {
|
||||
type: file.type,
|
||||
kind: "file",
|
||||
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.
|
||||
*/
|
||||
export const parseClipboard = async (
|
||||
dataList: ParsedDataTranferList,
|
||||
event: ClipboardEvent,
|
||||
isPlainPaste = false,
|
||||
): Promise<ClipboardData> => {
|
||||
const parsedEventData = await parseClipboardEventTextData(
|
||||
dataList,
|
||||
event,
|
||||
isPlainPaste,
|
||||
);
|
||||
|
||||
@@ -664,14 +519,3 @@ const copyTextViaExecCommand = (text: string | null) => {
|
||||
|
||||
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,118 +91,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
pointer-events: auto;
|
||||
|
||||
--default-button-size: 2rem;
|
||||
|
||||
.compact-action-button {
|
||||
width: var(--mobile-action-button-size);
|
||||
height: var(--mobile-action-button-size);
|
||||
border: none;
|
||||
border-radius: var(--border-radius-lg);
|
||||
color: var(--color-on-surface);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
background: var(--mobile-action-button-bg);
|
||||
|
||||
svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: var(
|
||||
--color-surface-primary-container,
|
||||
var(--mobile-action-button-bg)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ToolIcon {
|
||||
.ToolIcon__icon {
|
||||
width: var(--mobile-action-button-size);
|
||||
height: var(--mobile-action-button-size);
|
||||
|
||||
background: var(--mobile-action-button-bg);
|
||||
|
||||
&:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.compact-shape-actions-island {
|
||||
width: fit-content;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.mobile-shape-actions {
|
||||
z-index: 999;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
background: transparent;
|
||||
border-radius: var(--border-radius-lg);
|
||||
box-shadow: none;
|
||||
overflow: none;
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
}
|
||||
|
||||
.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,6 +1,5 @@
|
||||
import clsx from "clsx";
|
||||
import { useRef, useState } from "react";
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
import { useState } from "react";
|
||||
|
||||
import {
|
||||
CLASSES,
|
||||
@@ -12,16 +11,18 @@ import {
|
||||
import {
|
||||
shouldAllowVerticalAlign,
|
||||
suppportsHorizontalAlign,
|
||||
} from "@excalidraw/element";
|
||||
|
||||
import {
|
||||
hasBoundTextElement,
|
||||
isElbowArrow,
|
||||
isImageElement,
|
||||
isLinearElement,
|
||||
isTextElement,
|
||||
isArrowElement,
|
||||
hasStrokeColor,
|
||||
toolIsArrow,
|
||||
} from "@excalidraw/element";
|
||||
|
||||
import { hasStrokeColor, toolIsArrow } from "@excalidraw/element";
|
||||
|
||||
import type {
|
||||
ExcalidrawElement,
|
||||
ExcalidrawElementType,
|
||||
@@ -45,21 +46,15 @@ import {
|
||||
hasStrokeWidth,
|
||||
} from "../scene";
|
||||
|
||||
import { getFormValue } from "../actions/actionProperties";
|
||||
|
||||
import { useTextEditorFocus } from "../hooks/useTextEditorFocus";
|
||||
|
||||
import { getToolbarTools } from "./shapes";
|
||||
|
||||
import "./Actions.scss";
|
||||
|
||||
import { useDevice, useExcalidrawContainer } from "./App";
|
||||
import { useDevice } from "./App";
|
||||
import Stack from "./Stack";
|
||||
import { ToolButton } from "./ToolButton";
|
||||
import { ToolPopover } from "./ToolPopover";
|
||||
import { Tooltip } from "./Tooltip";
|
||||
import DropdownMenu from "./dropdownMenu/DropdownMenu";
|
||||
import { PropertiesPopover } from "./PropertiesPopover";
|
||||
import {
|
||||
EmbedIcon,
|
||||
extraToolsIcon,
|
||||
@@ -68,32 +63,11 @@ import {
|
||||
laserPointerToolIcon,
|
||||
MagicIcon,
|
||||
LassoIcon,
|
||||
sharpArrowIcon,
|
||||
roundArrowIcon,
|
||||
elbowArrowIcon,
|
||||
TextSizeIcon,
|
||||
adjustmentsIcon,
|
||||
DotsHorizontalIcon,
|
||||
SelectionIcon,
|
||||
} from "./icons";
|
||||
|
||||
import { Island } from "./Island";
|
||||
|
||||
import type {
|
||||
AppClassProperties,
|
||||
AppProps,
|
||||
UIAppState,
|
||||
Zoom,
|
||||
AppState,
|
||||
} from "../types";
|
||||
import type { AppClassProperties, AppProps, UIAppState, Zoom } from "../types";
|
||||
import type { ActionManager } from "../actions/manager";
|
||||
|
||||
// Common CSS class combinations
|
||||
const PROPERTIES_CLASSES = clsx([
|
||||
CLASSES.SHAPE_ACTIONS_THEME_SCOPE,
|
||||
"properties-content",
|
||||
]);
|
||||
|
||||
export const canChangeStrokeColor = (
|
||||
appState: UIAppState,
|
||||
targetElements: ExcalidrawElement[],
|
||||
@@ -195,12 +169,8 @@ export const SelectedShapeActions = ({
|
||||
renderAction("changeStrokeWidth")}
|
||||
|
||||
{(appState.activeTool.type === "freedraw" ||
|
||||
targetElements.some((element) => element.type === "freedraw")) && (
|
||||
<>
|
||||
{renderAction("changeStrokeShape")}
|
||||
{renderAction("changeStrokeType")}
|
||||
</>
|
||||
)}
|
||||
targetElements.some((element) => element.type === "freedraw")) &&
|
||||
renderAction("changeStrokeShape")}
|
||||
|
||||
{(hasStrokeStyle(appState.activeTool.type) ||
|
||||
targetElements.some((element) => hasStrokeStyle(element.type))) && (
|
||||
@@ -310,761 +280,23 @@ export const SelectedShapeActions = ({
|
||||
);
|
||||
};
|
||||
|
||||
const CombinedShapeProperties = ({
|
||||
appState,
|
||||
renderAction,
|
||||
setAppState,
|
||||
targetElements,
|
||||
container,
|
||||
}: {
|
||||
targetElements: ExcalidrawElement[];
|
||||
appState: UIAppState;
|
||||
renderAction: ActionManager["renderAction"];
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
container: HTMLDivElement | null;
|
||||
}) => {
|
||||
const showFillIcons =
|
||||
(hasBackground(appState.activeTool.type) &&
|
||||
!isTransparent(appState.currentItemBackgroundColor)) ||
|
||||
targetElements.some(
|
||||
(element) =>
|
||||
hasBackground(element.type) && !isTransparent(element.backgroundColor),
|
||||
);
|
||||
|
||||
const shouldShowCombinedProperties =
|
||||
targetElements.length > 0 ||
|
||||
(appState.activeTool.type !== "selection" &&
|
||||
appState.activeTool.type !== "eraser" &&
|
||||
appState.activeTool.type !== "hand" &&
|
||||
appState.activeTool.type !== "laser" &&
|
||||
appState.activeTool.type !== "lasso");
|
||||
const isOpen = appState.openPopup === "compactStrokeStyles";
|
||||
|
||||
if (!shouldShowCombinedProperties) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="compact-action-item">
|
||||
<Popover.Root
|
||||
open={isOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
setAppState({ openPopup: "compactStrokeStyles" });
|
||||
} else {
|
||||
setAppState({ openPopup: null });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Popover.Trigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className={clsx("compact-action-button properties-trigger", {
|
||||
active: isOpen,
|
||||
})}
|
||||
title={t("labels.stroke")}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
setAppState({
|
||||
openPopup: isOpen ? null : "compactStrokeStyles",
|
||||
});
|
||||
}}
|
||||
>
|
||||
{adjustmentsIcon}
|
||||
</button>
|
||||
</Popover.Trigger>
|
||||
{isOpen && (
|
||||
<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>
|
||||
);
|
||||
};
|
||||
|
||||
const CombinedArrowProperties = ({
|
||||
appState,
|
||||
renderAction,
|
||||
setAppState,
|
||||
targetElements,
|
||||
container,
|
||||
app,
|
||||
}: {
|
||||
targetElements: ExcalidrawElement[];
|
||||
appState: UIAppState;
|
||||
renderAction: ActionManager["renderAction"];
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
container: HTMLDivElement | null;
|
||||
app: AppClassProperties;
|
||||
}) => {
|
||||
const showShowArrowProperties =
|
||||
toolIsArrow(appState.activeTool.type) ||
|
||||
targetElements.some((element) => toolIsArrow(element.type));
|
||||
const isOpen = appState.openPopup === "compactArrowProperties";
|
||||
|
||||
if (!showShowArrowProperties) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="compact-action-item">
|
||||
<Popover.Root
|
||||
open={isOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
setAppState({ openPopup: "compactArrowProperties" });
|
||||
} else {
|
||||
setAppState({ openPopup: null });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Popover.Trigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className={clsx("compact-action-button properties-trigger", {
|
||||
active: isOpen,
|
||||
})}
|
||||
title={t("labels.arrowtypes")}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
setAppState({
|
||||
openPopup: isOpen ? 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>
|
||||
{isOpen && (
|
||||
<PropertiesPopover
|
||||
container={container}
|
||||
className="properties-content"
|
||||
style={{ maxWidth: "13rem" }}
|
||||
onClose={() => {}}
|
||||
>
|
||||
{renderAction("changeArrowProperties")}
|
||||
</PropertiesPopover>
|
||||
)}
|
||||
</Popover.Root>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const CombinedTextProperties = ({
|
||||
appState,
|
||||
renderAction,
|
||||
setAppState,
|
||||
targetElements,
|
||||
container,
|
||||
elementsMap,
|
||||
}: {
|
||||
appState: UIAppState;
|
||||
renderAction: ActionManager["renderAction"];
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
targetElements: ExcalidrawElement[];
|
||||
container: HTMLDivElement | null;
|
||||
elementsMap: NonDeletedElementsMap | NonDeletedSceneElementsMap;
|
||||
}) => {
|
||||
const { saveCaretPosition, restoreCaretPosition } = useTextEditorFocus();
|
||||
const isOpen = appState.openPopup === "compactTextProperties";
|
||||
|
||||
return (
|
||||
<div className="compact-action-item">
|
||||
<Popover.Root
|
||||
open={isOpen}
|
||||
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={clsx("compact-action-button properties-trigger", {
|
||||
active: isOpen,
|
||||
})}
|
||||
title={t("labels.textAlign")}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (isOpen) {
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
||||
const CombinedExtraActions = ({
|
||||
appState,
|
||||
renderAction,
|
||||
targetElements,
|
||||
setAppState,
|
||||
container,
|
||||
app,
|
||||
showDuplicate,
|
||||
showDelete,
|
||||
}: {
|
||||
appState: UIAppState;
|
||||
targetElements: ExcalidrawElement[];
|
||||
renderAction: ActionManager["renderAction"];
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
container: HTMLDivElement | null;
|
||||
app: AppClassProperties;
|
||||
showDuplicate?: boolean;
|
||||
showDelete?: boolean;
|
||||
}) => {
|
||||
const isEditingTextOrNewElement = Boolean(
|
||||
appState.editingTextElement || appState.newElement,
|
||||
);
|
||||
const showCropEditorAction =
|
||||
!appState.croppingElementId &&
|
||||
targetElements.length === 1 &&
|
||||
isImageElement(targetElements[0]);
|
||||
const showLinkIcon = targetElements.length === 1;
|
||||
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";
|
||||
const isOpen = appState.openPopup === "compactOtherProperties";
|
||||
|
||||
if (isEditingTextOrNewElement || targetElements.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="compact-action-item">
|
||||
<Popover.Root
|
||||
open={isOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
setAppState({ openPopup: "compactOtherProperties" });
|
||||
} else {
|
||||
setAppState({ openPopup: null });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Popover.Trigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className={clsx("compact-action-button properties-trigger", {
|
||||
active: isOpen,
|
||||
})}
|
||||
title={t("labels.actions")}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setAppState({
|
||||
openPopup: isOpen ? null : "compactOtherProperties",
|
||||
});
|
||||
}}
|
||||
>
|
||||
{DotsHorizontalIcon}
|
||||
</button>
|
||||
</Popover.Trigger>
|
||||
{isOpen && (
|
||||
<PropertiesPopover
|
||||
className={PROPERTIES_CLASSES}
|
||||
container={container}
|
||||
style={{
|
||||
maxWidth: "12rem",
|
||||
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")}
|
||||
{showDuplicate && renderAction("duplicateSelection")}
|
||||
{showDelete && renderAction("deleteSelectedElements")}
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</PropertiesPopover>
|
||||
)}
|
||||
</Popover.Root>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const LinearEditorAction = ({
|
||||
appState,
|
||||
renderAction,
|
||||
targetElements,
|
||||
}: {
|
||||
appState: UIAppState;
|
||||
targetElements: ExcalidrawElement[];
|
||||
renderAction: ActionManager["renderAction"];
|
||||
}) => {
|
||||
const showLineEditorAction =
|
||||
!appState.selectedLinearElement?.isEditing &&
|
||||
targetElements.length === 1 &&
|
||||
isLinearElement(targetElements[0]) &&
|
||||
!isElbowArrow(targetElements[0]);
|
||||
|
||||
if (!showLineEditorAction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="compact-action-item">
|
||||
{renderAction("toggleLinearEditor")}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
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 { container } = useExcalidrawContainer();
|
||||
|
||||
const isEditingTextOrNewElement = Boolean(
|
||||
appState.editingTextElement || appState.newElement,
|
||||
);
|
||||
|
||||
const showLineEditorAction =
|
||||
!appState.selectedLinearElement?.isEditing &&
|
||||
targetElements.length === 1 &&
|
||||
isLinearElement(targetElements[0]) &&
|
||||
!isElbowArrow(targetElements[0]);
|
||||
|
||||
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>
|
||||
)}
|
||||
|
||||
<CombinedShapeProperties
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
setAppState={setAppState}
|
||||
targetElements={targetElements}
|
||||
container={container}
|
||||
/>
|
||||
|
||||
<CombinedArrowProperties
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
setAppState={setAppState}
|
||||
targetElements={targetElements}
|
||||
container={container}
|
||||
app={app}
|
||||
/>
|
||||
{/* 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>
|
||||
<CombinedTextProperties
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
setAppState={setAppState}
|
||||
targetElements={targetElements}
|
||||
container={container}
|
||||
elementsMap={elementsMap}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 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>
|
||||
)}
|
||||
|
||||
<CombinedExtraActions
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
targetElements={targetElements}
|
||||
setAppState={setAppState}
|
||||
container={container}
|
||||
app={app}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const MobileShapeActions = ({
|
||||
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 { container } = useExcalidrawContainer();
|
||||
const mobileActionsRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const ACTIONS_WIDTH =
|
||||
mobileActionsRef.current?.getBoundingClientRect()?.width ?? 0;
|
||||
|
||||
// 7 actions + 2 for undo/redo
|
||||
const MIN_ACTIONS = 9;
|
||||
|
||||
const GAP = 6;
|
||||
const WIDTH = 32;
|
||||
|
||||
const MIN_WIDTH = MIN_ACTIONS * WIDTH + (MIN_ACTIONS - 1) * GAP;
|
||||
|
||||
const ADDITIONAL_WIDTH = WIDTH + GAP;
|
||||
|
||||
const showDeleteOutside = ACTIONS_WIDTH >= MIN_WIDTH + ADDITIONAL_WIDTH;
|
||||
const showDuplicateOutside =
|
||||
ACTIONS_WIDTH >= MIN_WIDTH + 2 * ADDITIONAL_WIDTH;
|
||||
|
||||
return (
|
||||
<Island
|
||||
className="compact-shape-actions mobile-shape-actions"
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
boxShadow: "none",
|
||||
padding: 0,
|
||||
zIndex: 2,
|
||||
backgroundColor: "transparent",
|
||||
height: WIDTH * 1.35,
|
||||
marginBottom: 4,
|
||||
alignItems: "center",
|
||||
gap: GAP,
|
||||
pointerEvents: "none",
|
||||
}}
|
||||
ref={mobileActionsRef}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
gap: GAP,
|
||||
flex: 1,
|
||||
}}
|
||||
>
|
||||
{canChangeStrokeColor(appState, targetElements) && (
|
||||
<div className={clsx("compact-action-item")}>
|
||||
{renderAction("changeStrokeColor")}
|
||||
</div>
|
||||
)}
|
||||
{canChangeBackgroundColor(appState, targetElements) && (
|
||||
<div className="compact-action-item">
|
||||
{renderAction("changeBackgroundColor")}
|
||||
</div>
|
||||
)}
|
||||
<CombinedShapeProperties
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
setAppState={setAppState}
|
||||
targetElements={targetElements}
|
||||
container={container}
|
||||
/>
|
||||
{/* Combined Arrow Properties */}
|
||||
<CombinedArrowProperties
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
setAppState={setAppState}
|
||||
targetElements={targetElements}
|
||||
container={container}
|
||||
app={app}
|
||||
/>
|
||||
{/* Linear Editor */}
|
||||
<LinearEditorAction
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
targetElements={targetElements}
|
||||
/>
|
||||
{/* Text Properties */}
|
||||
{(appState.activeTool.type === "text" ||
|
||||
targetElements.some(isTextElement)) && (
|
||||
<>
|
||||
<div className="compact-action-item">
|
||||
{renderAction("changeFontFamily")}
|
||||
</div>
|
||||
<CombinedTextProperties
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
setAppState={setAppState}
|
||||
targetElements={targetElements}
|
||||
container={container}
|
||||
elementsMap={elementsMap}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Combined Other Actions */}
|
||||
<CombinedExtraActions
|
||||
appState={appState}
|
||||
renderAction={renderAction}
|
||||
targetElements={targetElements}
|
||||
setAppState={setAppState}
|
||||
container={container}
|
||||
app={app}
|
||||
showDuplicate={!showDuplicateOutside}
|
||||
showDelete={!showDeleteOutside}
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
gap: GAP,
|
||||
}}
|
||||
>
|
||||
<div className="compact-action-item">{renderAction("undo")}</div>
|
||||
<div className="compact-action-item">{renderAction("redo")}</div>
|
||||
{showDuplicateOutside && (
|
||||
<div className="compact-action-item">
|
||||
{renderAction("duplicateSelection")}
|
||||
</div>
|
||||
)}
|
||||
{showDeleteOutside && (
|
||||
<div className="compact-action-item">
|
||||
{renderAction("deleteSelectedElements")}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Island>
|
||||
);
|
||||
};
|
||||
|
||||
export const ShapesSwitcher = ({
|
||||
activeTool,
|
||||
setAppState,
|
||||
appState,
|
||||
app,
|
||||
UIOptions,
|
||||
}: {
|
||||
activeTool: UIAppState["activeTool"];
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
appState: UIAppState;
|
||||
app: AppClassProperties;
|
||||
UIOptions: AppProps["UIOptions"];
|
||||
}) => {
|
||||
const [isExtraToolsMenuOpen, setIsExtraToolsMenuOpen] = useState(false);
|
||||
|
||||
const SELECTION_TOOLS = [
|
||||
{
|
||||
type: "selection",
|
||||
icon: SelectionIcon,
|
||||
title: capitalizeString(t("toolBar.selection")),
|
||||
},
|
||||
{
|
||||
type: "lasso",
|
||||
icon: LassoIcon,
|
||||
title: capitalizeString(t("toolBar.lasso")),
|
||||
},
|
||||
] as const;
|
||||
|
||||
const frameToolSelected = activeTool.type === "frame";
|
||||
const laserToolSelected = activeTool.type === "laser";
|
||||
const lassoToolSelected =
|
||||
app.state.stylesPanelMode === "full" &&
|
||||
activeTool.type === "lasso" &&
|
||||
app.state.preferredSelectionTool.type !== "lasso";
|
||||
activeTool.type === "lasso" && app.defaultSelectionTool !== "lasso";
|
||||
|
||||
const embeddableToolSelected = activeTool.type === "embeddable";
|
||||
|
||||
@@ -1091,40 +323,6 @@ export const ShapesSwitcher = ({
|
||||
const shortcut = letter
|
||||
? `${letter} ${t("helpDialog.or")} ${numericKey}`
|
||||
: `${numericKey}`;
|
||||
// when in compact styles panel mode (tablet)
|
||||
// use a ToolPopover for selection/lasso toggle as well
|
||||
if (
|
||||
(value === "selection" || value === "lasso") &&
|
||||
app.state.stylesPanelMode === "compact"
|
||||
) {
|
||||
return (
|
||||
<ToolPopover
|
||||
key={"selection-popover"}
|
||||
app={app}
|
||||
options={SELECTION_TOOLS}
|
||||
activeTool={activeTool}
|
||||
defaultOption={app.state.preferredSelectionTool.type}
|
||||
namePrefix="selectionType"
|
||||
title={capitalizeString(t("toolBar.selection"))}
|
||||
data-testid="toolbar-selection"
|
||||
onToolChange={(type: string) => {
|
||||
if (type === "selection" || type === "lasso") {
|
||||
app.setActiveTool({ type });
|
||||
setAppState({
|
||||
preferredSelectionTool: { type, initialized: true },
|
||||
});
|
||||
}
|
||||
}}
|
||||
displayedOption={
|
||||
SELECTION_TOOLS.find(
|
||||
(tool) =>
|
||||
tool.type === app.state.preferredSelectionTool.type,
|
||||
) || SELECTION_TOOLS[0]
|
||||
}
|
||||
fillable={activeTool.type === "selection"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ToolButton
|
||||
@@ -1140,12 +338,12 @@ export const ShapesSwitcher = ({
|
||||
aria-keyshortcuts={shortcut}
|
||||
data-testid={`toolbar-${value}`}
|
||||
onPointerDown={({ pointerType }) => {
|
||||
if (!app.state.penDetected && pointerType === "pen") {
|
||||
if (!appState.penDetected && pointerType === "pen") {
|
||||
app.togglePenMode(true);
|
||||
}
|
||||
|
||||
if (value === "selection") {
|
||||
if (app.state.activeTool.type === "selection") {
|
||||
if (appState.activeTool.type === "selection") {
|
||||
app.setActiveTool({ type: "lasso" });
|
||||
} else {
|
||||
app.setActiveTool({ type: "selection" });
|
||||
@@ -1153,7 +351,7 @@ export const ShapesSwitcher = ({
|
||||
}
|
||||
}}
|
||||
onChange={({ pointerType }) => {
|
||||
if (app.state.activeTool.type !== value) {
|
||||
if (appState.activeTool.type !== value) {
|
||||
trackEvent("toolbar", value, "ui");
|
||||
}
|
||||
if (value === "image") {
|
||||
@@ -1182,10 +380,7 @@ export const ShapesSwitcher = ({
|
||||
// on top of it
|
||||
(laserToolSelected && !app.props.isCollaborating),
|
||||
})}
|
||||
onToggle={() => {
|
||||
setIsExtraToolsMenuOpen(!isExtraToolsMenuOpen);
|
||||
setAppState({ openMenu: null, openPopup: null });
|
||||
}}
|
||||
onToggle={() => setIsExtraToolsMenuOpen(!isExtraToolsMenuOpen)}
|
||||
title={t("toolBar.extraTools")}
|
||||
>
|
||||
{frameToolSelected
|
||||
@@ -1229,7 +424,7 @@ export const ShapesSwitcher = ({
|
||||
>
|
||||
{t("toolBar.laser")}
|
||||
</DropdownMenu.Item>
|
||||
{app.state.stylesPanelMode === "full" && (
|
||||
{app.defaultSelectionTool !== "lasso" && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setActiveTool({ type: "lasso" })}
|
||||
icon={LassoIcon}
|
||||
@@ -1251,14 +446,16 @@ export const ShapesSwitcher = ({
|
||||
{t("toolBar.mermaidToExcalidraw")}
|
||||
</DropdownMenu.Item>
|
||||
{app.props.aiEnabled !== false && app.plugins.diagramToCode && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.onMagicframeToolSelect()}
|
||||
icon={MagicIcon}
|
||||
data-testid="toolbar-magicframe"
|
||||
>
|
||||
{t("toolBar.magicframe")}
|
||||
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
|
||||
</DropdownMenu.Item>
|
||||
<>
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.onMagicframeToolSelect()}
|
||||
icon={MagicIcon}
|
||||
data-testid="toolbar-magicframe"
|
||||
>
|
||||
{t("toolBar.magicframe")}
|
||||
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
|
||||
</DropdownMenu.Item>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,8 @@
|
||||
import clsx from "clsx";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { KEYS } from "@excalidraw/common";
|
||||
import { KEYS, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import { getShortcutKey } from "../..//shortcut";
|
||||
import { useAtom } from "../../editor-jotai";
|
||||
import { t } from "../../i18n";
|
||||
import { useDevice } from "../App";
|
||||
|
||||
@@ -7,12 +7,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.color-picker__title {
|
||||
padding: 0 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.color-picker__heading {
|
||||
padding: 0 0.5rem;
|
||||
font-size: 0.75rem;
|
||||
@@ -28,12 +22,6 @@
|
||||
@include isMobile {
|
||||
max-width: 11rem;
|
||||
}
|
||||
|
||||
&.color-picker-container--no-top-picks {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
grid-template-columns: unset;
|
||||
}
|
||||
}
|
||||
|
||||
.color-picker__top-picks {
|
||||
@@ -92,16 +80,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.color-picker__button-background {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
&.active {
|
||||
.color-picker__button-outline {
|
||||
position: absolute;
|
||||
@@ -163,15 +141,6 @@
|
||||
width: 1.625rem;
|
||||
height: 1.625rem;
|
||||
}
|
||||
|
||||
&.compact-sizing {
|
||||
width: var(--mobile-action-button-size);
|
||||
height: var(--mobile-action-button-size);
|
||||
}
|
||||
|
||||
&.mobile-border {
|
||||
border: 1px solid var(--mobile-color-border);
|
||||
}
|
||||
}
|
||||
|
||||
.color-picker__button__hotkey-label {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
import clsx from "clsx";
|
||||
import { useRef, useEffect } from "react";
|
||||
import { useRef } from "react";
|
||||
|
||||
import {
|
||||
COLOR_OUTLINE_CONTRAST_THRESHOLD,
|
||||
COLOR_PALETTE,
|
||||
isTransparent,
|
||||
isWritableElement,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import type { ColorTuple, ColorPaletteCustom } from "@excalidraw/common";
|
||||
@@ -19,12 +18,7 @@ import { useExcalidrawContainer } from "../App";
|
||||
import { ButtonSeparator } from "../ButtonSeparator";
|
||||
import { activeEyeDropperAtom } from "../EyeDropper";
|
||||
import { PropertiesPopover } from "../PropertiesPopover";
|
||||
import { slashIcon, strokeIcon } from "../icons";
|
||||
import {
|
||||
saveCaretPosition,
|
||||
restoreCaretPosition,
|
||||
temporarilyDisableTextEditorBlur,
|
||||
} from "../../hooks/useTextEditorFocus";
|
||||
import { slashIcon } from "../icons";
|
||||
|
||||
import { ColorInput } from "./ColorInput";
|
||||
import { Picker } from "./Picker";
|
||||
@@ -73,7 +67,6 @@ interface ColorPickerProps {
|
||||
palette?: ColorPaletteCustom | null;
|
||||
topPicks?: ColorTuple;
|
||||
updateData: (formData?: any) => void;
|
||||
compactMode?: boolean;
|
||||
}
|
||||
|
||||
const ColorPickerPopupContent = ({
|
||||
@@ -84,8 +77,6 @@ const ColorPickerPopupContent = ({
|
||||
elements,
|
||||
palette = COLOR_PALETTE,
|
||||
updateData,
|
||||
getOpenPopup,
|
||||
appState,
|
||||
}: Pick<
|
||||
ColorPickerProps,
|
||||
| "type"
|
||||
@@ -95,10 +86,7 @@ const ColorPickerPopupContent = ({
|
||||
| "elements"
|
||||
| "palette"
|
||||
| "updateData"
|
||||
| "appState"
|
||||
> & {
|
||||
getOpenPopup: () => AppState["openPopup"];
|
||||
}) => {
|
||||
>) => {
|
||||
const { container } = useExcalidrawContainer();
|
||||
const [, setActiveColorPickerSection] = useAtom(activeColorPickerSectionAtom);
|
||||
|
||||
@@ -129,13 +117,9 @@ const ColorPickerPopupContent = ({
|
||||
<PropertiesPopover
|
||||
container={container}
|
||||
style={{ maxWidth: "13rem" }}
|
||||
// Improve focus handling for text editing scenarios
|
||||
preventAutoFocusOnTouch={!!appState.editingTextElement}
|
||||
onFocusOutside={(event) => {
|
||||
// refocus due to eye dropper
|
||||
if (!isWritableElement(event.target)) {
|
||||
focusPickerContent();
|
||||
}
|
||||
focusPickerContent();
|
||||
event.preventDefault();
|
||||
}}
|
||||
onPointerDownOutside={(event) => {
|
||||
@@ -147,23 +131,8 @@ const ColorPickerPopupContent = ({
|
||||
}
|
||||
}}
|
||||
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);
|
||||
|
||||
// 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 ? (
|
||||
@@ -172,17 +141,7 @@ const ColorPickerPopupContent = ({
|
||||
palette={palette}
|
||||
color={color}
|
||||
onChange={(changedColor) => {
|
||||
// Save caret position before color change if editing text
|
||||
const savedSelection = appState.editingTextElement
|
||||
? saveCaretPosition()
|
||||
: null;
|
||||
|
||||
onChange(changedColor);
|
||||
|
||||
// Restore caret position after color change if editing text
|
||||
if (appState.editingTextElement && savedSelection) {
|
||||
restoreCaretPosition(savedSelection);
|
||||
}
|
||||
}}
|
||||
onEyeDropperToggle={(force) => {
|
||||
setEyeDropperState((state) => {
|
||||
@@ -209,18 +168,12 @@ const ColorPickerPopupContent = ({
|
||||
if (eyeDropperState) {
|
||||
setEyeDropperState(null);
|
||||
} else {
|
||||
// close explicitly on Escape
|
||||
updateData({ openPopup: null });
|
||||
}
|
||||
}}
|
||||
type={type}
|
||||
elements={elements}
|
||||
updateData={updateData}
|
||||
showTitle={
|
||||
appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile"
|
||||
}
|
||||
showHotKey={appState.stylesPanelMode !== "mobile"}
|
||||
>
|
||||
{colorInputJSX}
|
||||
</Picker>
|
||||
@@ -235,32 +188,11 @@ const ColorPickerTrigger = ({
|
||||
label,
|
||||
color,
|
||||
type,
|
||||
stylesPanelMode,
|
||||
mode = "background",
|
||||
onToggle,
|
||||
editingTextElement,
|
||||
}: {
|
||||
color: string | null;
|
||||
label: string;
|
||||
type: ColorPickerType;
|
||||
stylesPanelMode?: AppState["stylesPanelMode"];
|
||||
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 (
|
||||
<Popover.Trigger
|
||||
type="button"
|
||||
@@ -268,9 +200,6 @@ const ColorPickerTrigger = ({
|
||||
"is-transparent": !color || color === "transparent",
|
||||
"has-outline":
|
||||
!color || !isColorDark(color, COLOR_OUTLINE_CONTRAST_THRESHOLD),
|
||||
"compact-sizing":
|
||||
stylesPanelMode === "compact" || stylesPanelMode === "mobile",
|
||||
"mobile-border": stylesPanelMode === "mobile",
|
||||
})}
|
||||
aria-label={label}
|
||||
style={color ? { "--swatch-color": color } : undefined}
|
||||
@@ -279,26 +208,8 @@ const ColorPickerTrigger = ({
|
||||
? t("labels.showStroke")
|
||||
: t("labels.showBackground")
|
||||
}
|
||||
data-openpopup={type}
|
||||
onClick={handleClick}
|
||||
>
|
||||
<div className="color-picker__button-outline">{!color && slashIcon}</div>
|
||||
{(stylesPanelMode === "compact" || stylesPanelMode === "mobile") &&
|
||||
color &&
|
||||
mode === "stroke" && (
|
||||
<div className="color-picker__button-background">
|
||||
<span
|
||||
style={{
|
||||
color:
|
||||
color && isColorDark(color, COLOR_OUTLINE_CONTRAST_THRESHOLD)
|
||||
? "#fff"
|
||||
: "#111",
|
||||
}}
|
||||
>
|
||||
{strokeIcon}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</Popover.Trigger>
|
||||
);
|
||||
};
|
||||
@@ -314,62 +225,24 @@ export const ColorPicker = ({
|
||||
updateData,
|
||||
appState,
|
||||
}: ColorPickerProps) => {
|
||||
const openRef = useRef(appState.openPopup);
|
||||
useEffect(() => {
|
||||
openRef.current = appState.openPopup;
|
||||
}, [appState.openPopup]);
|
||||
const compactMode =
|
||||
type !== "canvasBackground" &&
|
||||
(appState.stylesPanelMode === "compact" ||
|
||||
appState.stylesPanelMode === "mobile");
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
className={clsx("color-picker-container", {
|
||||
"color-picker-container--no-top-picks": compactMode,
|
||||
})}
|
||||
>
|
||||
{!compactMode && (
|
||||
<TopPicks
|
||||
activeColor={color}
|
||||
onChange={onChange}
|
||||
type={type}
|
||||
topPicks={topPicks}
|
||||
/>
|
||||
)}
|
||||
{!compactMode && <ButtonSeparator />}
|
||||
<div role="dialog" aria-modal="true" className="color-picker-container">
|
||||
<TopPicks
|
||||
activeColor={color}
|
||||
onChange={onChange}
|
||||
type={type}
|
||||
topPicks={topPicks}
|
||||
/>
|
||||
<ButtonSeparator />
|
||||
<Popover.Root
|
||||
open={appState.openPopup === type}
|
||||
onOpenChange={(open) => {
|
||||
if (open) {
|
||||
updateData({ openPopup: type });
|
||||
}
|
||||
updateData({ openPopup: open ? type : null });
|
||||
}}
|
||||
>
|
||||
{/* serves as an active color indicator as well */}
|
||||
<ColorPickerTrigger
|
||||
color={color}
|
||||
label={label}
|
||||
type={type}
|
||||
stylesPanelMode={appState.stylesPanelMode}
|
||||
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 });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<ColorPickerTrigger color={color} label={label} type={type} />
|
||||
{/* popup content */}
|
||||
{appState.openPopup === type && (
|
||||
<ColorPickerPopupContent
|
||||
@@ -380,8 +253,6 @@ export const ColorPicker = ({
|
||||
elements={elements}
|
||||
palette={palette}
|
||||
updateData={updateData}
|
||||
getOpenPopup={() => openRef.current}
|
||||
appState={appState}
|
||||
/>
|
||||
)}
|
||||
</Popover.Root>
|
||||
|
||||
@@ -37,10 +37,8 @@ interface PickerProps {
|
||||
palette: ColorPaletteCustom;
|
||||
updateData: (formData?: any) => void;
|
||||
children?: React.ReactNode;
|
||||
showTitle?: boolean;
|
||||
onEyeDropperToggle: (force?: boolean) => void;
|
||||
onEscape: (event: React.KeyboardEvent | KeyboardEvent) => void;
|
||||
showHotKey?: boolean;
|
||||
}
|
||||
|
||||
export const Picker = React.forwardRef(
|
||||
@@ -53,21 +51,11 @@ export const Picker = React.forwardRef(
|
||||
palette,
|
||||
updateData,
|
||||
children,
|
||||
showTitle,
|
||||
onEyeDropperToggle,
|
||||
onEscape,
|
||||
showHotKey = true,
|
||||
}: PickerProps,
|
||||
ref,
|
||||
) => {
|
||||
const title = showTitle
|
||||
? type === "elementStroke"
|
||||
? t("labels.stroke")
|
||||
: type === "elementBackground"
|
||||
? t("labels.background")
|
||||
: null
|
||||
: null;
|
||||
|
||||
const [customColors] = React.useState(() => {
|
||||
if (type === "canvasBackground") {
|
||||
return [];
|
||||
@@ -166,8 +154,6 @@ export const Picker = React.forwardRef(
|
||||
// to allow focusing by clicking but not by tabbing
|
||||
tabIndex={-1}
|
||||
>
|
||||
{title && <div className="color-picker__title">{title}</div>}
|
||||
|
||||
{!!customColors.length && (
|
||||
<div>
|
||||
<PickerHeading>
|
||||
@@ -189,18 +175,12 @@ export const Picker = React.forwardRef(
|
||||
palette={palette}
|
||||
onChange={onChange}
|
||||
activeShade={activeShade}
|
||||
showHotKey={showHotKey}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<PickerHeading>{t("colorPicker.shades")}</PickerHeading>
|
||||
<ShadeList
|
||||
color={color}
|
||||
onChange={onChange}
|
||||
palette={palette}
|
||||
showHotKey={showHotKey}
|
||||
/>
|
||||
<ShadeList color={color} onChange={onChange} palette={palette} />
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
@@ -20,7 +20,6 @@ interface PickerColorListProps {
|
||||
color: string | null;
|
||||
onChange: (color: string) => void;
|
||||
activeShade: number;
|
||||
showHotKey?: boolean;
|
||||
}
|
||||
|
||||
const PickerColorList = ({
|
||||
@@ -28,7 +27,6 @@ const PickerColorList = ({
|
||||
color,
|
||||
onChange,
|
||||
activeShade,
|
||||
showHotKey = true,
|
||||
}: PickerColorListProps) => {
|
||||
const colorObj = getColorNameAndShadeFromColor({
|
||||
color,
|
||||
@@ -84,7 +82,7 @@ const PickerColorList = ({
|
||||
key={key}
|
||||
>
|
||||
<div className="color-picker__button-outline" />
|
||||
{showHotKey && <HotkeyLabel color={color} keyLabel={keybinding} />}
|
||||
<HotkeyLabel color={color} keyLabel={keybinding} />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -16,15 +16,9 @@ interface ShadeListProps {
|
||||
color: string | null;
|
||||
onChange: (color: string) => void;
|
||||
palette: ColorPaletteCustom;
|
||||
showHotKey?: boolean;
|
||||
}
|
||||
|
||||
export const ShadeList = ({
|
||||
color,
|
||||
onChange,
|
||||
palette,
|
||||
showHotKey,
|
||||
}: ShadeListProps) => {
|
||||
export const ShadeList = ({ color, onChange, palette }: ShadeListProps) => {
|
||||
const colorObj = getColorNameAndShadeFromColor({
|
||||
color: color || "transparent",
|
||||
palette,
|
||||
@@ -73,9 +67,7 @@ export const ShadeList = ({
|
||||
}}
|
||||
>
|
||||
<div className="color-picker__button-outline" />
|
||||
{showHotKey && (
|
||||
<HotkeyLabel color={color} keyLabel={i + 1} isShade />
|
||||
)}
|
||||
<HotkeyLabel color={color} keyLabel={i + 1} isShade />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -100,19 +100,6 @@ $verticalBreakpoint: 861px;
|
||||
border-radius: var(--border-radius-lg);
|
||||
cursor: pointer;
|
||||
|
||||
--icon-size: 1rem;
|
||||
|
||||
&.command-item-large {
|
||||
height: 2.75rem;
|
||||
--icon-size: 1.5rem;
|
||||
|
||||
.icon {
|
||||
width: var(--icon-size);
|
||||
height: var(--icon-size);
|
||||
margin-right: 0.625rem;
|
||||
}
|
||||
}
|
||||
|
||||
&:active {
|
||||
background-color: var(--color-surface-low);
|
||||
}
|
||||
@@ -143,17 +130,9 @@ $verticalBreakpoint: 861px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: var(--icon-size, 1rem);
|
||||
height: var(--icon-size, 1rem);
|
||||
margin-right: 0.375rem;
|
||||
|
||||
.library-item-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
margin-right: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
import clsx from "clsx";
|
||||
import fuzzy from "fuzzy";
|
||||
import { useEffect, useRef, useMemo, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import {
|
||||
DEFAULT_SIDEBAR,
|
||||
EVENT,
|
||||
KEYS,
|
||||
capitalizeString,
|
||||
getShortcutKey,
|
||||
isWritableElement,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import { actionToggleShapeSwitch } from "@excalidraw/excalidraw/actions/actionToggleShapeSwitch";
|
||||
|
||||
import { getShortcutKey } from "@excalidraw/excalidraw/shortcut";
|
||||
|
||||
import type { MarkRequired } from "@excalidraw/common/utility-types";
|
||||
|
||||
import {
|
||||
@@ -62,21 +61,12 @@ import { useStable } from "../../hooks/useStable";
|
||||
|
||||
import { Ellipsify } from "../Ellipsify";
|
||||
|
||||
import {
|
||||
distributeLibraryItemsOnSquareGrid,
|
||||
libraryItemsAtom,
|
||||
} from "../../data/library";
|
||||
|
||||
import {
|
||||
useLibraryCache,
|
||||
useLibraryItemSvg,
|
||||
} from "../../hooks/useLibraryItemSvg";
|
||||
|
||||
import * as defaultItems from "./defaultCommandPaletteItems";
|
||||
|
||||
import "./CommandPalette.scss";
|
||||
|
||||
import type { CommandPaletteItem } from "./types";
|
||||
import type { AppProps, AppState, LibraryItem, UIAppState } from "../../types";
|
||||
import type { AppProps, AppState, UIAppState } from "../../types";
|
||||
import type { ShortcutName } from "../../actions/shortcuts";
|
||||
import type { TranslationKeys } from "../../i18n";
|
||||
import type { Action } from "../../actions/types";
|
||||
@@ -90,7 +80,6 @@ export const DEFAULT_CATEGORIES = {
|
||||
editor: "Editor",
|
||||
elements: "Elements",
|
||||
links: "Links",
|
||||
library: "Library",
|
||||
};
|
||||
|
||||
const getCategoryOrder = (category: string) => {
|
||||
@@ -218,34 +207,6 @@ function CommandPaletteInner({
|
||||
appProps,
|
||||
});
|
||||
|
||||
const [libraryItemsData] = useAtom(libraryItemsAtom);
|
||||
const libraryCommands: CommandPaletteItem[] = useMemo(() => {
|
||||
return (
|
||||
libraryItemsData.libraryItems
|
||||
?.filter(
|
||||
(libraryItem): libraryItem is MarkRequired<LibraryItem, "name"> =>
|
||||
!!libraryItem.name,
|
||||
)
|
||||
.map((libraryItem) => ({
|
||||
label: libraryItem.name,
|
||||
icon: (
|
||||
<LibraryItemIcon
|
||||
id={libraryItem.id}
|
||||
elements={libraryItem.elements}
|
||||
/>
|
||||
),
|
||||
category: "Library",
|
||||
order: getCategoryOrder("Library"),
|
||||
haystack: deburr(libraryItem.name),
|
||||
perform: () => {
|
||||
app.onInsertElements(
|
||||
distributeLibraryItemsOnSquareGrid([libraryItem]),
|
||||
);
|
||||
},
|
||||
})) || []
|
||||
);
|
||||
}, [app, libraryItemsData.libraryItems]);
|
||||
|
||||
useEffect(() => {
|
||||
// these props change often and we don't want them to re-run the effect
|
||||
// which would renew `allCommands`, cascading down and resetting state.
|
||||
@@ -477,6 +438,7 @@ function CommandPaletteInner({
|
||||
},
|
||||
perform: () => {
|
||||
setAppState((prevState) => ({
|
||||
openMenu: prevState.openMenu === "shape" ? null : "shape",
|
||||
openPopup: "elementStroke",
|
||||
}));
|
||||
},
|
||||
@@ -496,6 +458,7 @@ function CommandPaletteInner({
|
||||
},
|
||||
perform: () => {
|
||||
setAppState((prevState) => ({
|
||||
openMenu: prevState.openMenu === "shape" ? null : "shape",
|
||||
openPopup: "elementBackground",
|
||||
}));
|
||||
},
|
||||
@@ -625,9 +588,8 @@ function CommandPaletteInner({
|
||||
|
||||
setAllCommands(allCommands);
|
||||
setLastUsed(
|
||||
[...allCommands, ...libraryCommands].find(
|
||||
(command) => command.label === lastUsed?.label,
|
||||
) ?? null,
|
||||
allCommands.find((command) => command.label === lastUsed?.label) ??
|
||||
null,
|
||||
);
|
||||
}
|
||||
}, [
|
||||
@@ -638,7 +600,6 @@ function CommandPaletteInner({
|
||||
lastUsed?.label,
|
||||
setLastUsed,
|
||||
setAppState,
|
||||
libraryCommands,
|
||||
]);
|
||||
|
||||
const [commandSearch, setCommandSearch] = useState("");
|
||||
@@ -835,17 +796,9 @@ function CommandPaletteInner({
|
||||
return nextCommandsByCategory;
|
||||
};
|
||||
|
||||
let matchingCommands =
|
||||
commandSearch?.length > 1
|
||||
? [
|
||||
...allCommands
|
||||
.filter(isCommandAvailable)
|
||||
.sort((a, b) => a.order - b.order),
|
||||
...libraryCommands,
|
||||
]
|
||||
: allCommands
|
||||
.filter(isCommandAvailable)
|
||||
.sort((a, b) => a.order - b.order);
|
||||
let matchingCommands = allCommands
|
||||
.filter(isCommandAvailable)
|
||||
.sort((a, b) => a.order - b.order);
|
||||
|
||||
const showLastUsed =
|
||||
!commandSearch && lastUsed && isCommandAvailable(lastUsed);
|
||||
@@ -869,20 +822,14 @@ function CommandPaletteInner({
|
||||
);
|
||||
matchingCommands = fuzzy
|
||||
.filter(_query, matchingCommands, {
|
||||
extract: (command) => command.haystack ?? "",
|
||||
extract: (command) => command.haystack,
|
||||
})
|
||||
.sort((a, b) => b.score - a.score)
|
||||
.map((item) => item.original);
|
||||
|
||||
setCommandsByCategory(getNextCommandsByCategory(matchingCommands));
|
||||
setCurrentCommand(matchingCommands[0] ?? null);
|
||||
}, [
|
||||
commandSearch,
|
||||
allCommands,
|
||||
isCommandAvailable,
|
||||
lastUsed,
|
||||
libraryCommands,
|
||||
]);
|
||||
}, [commandSearch, allCommands, isCommandAvailable, lastUsed]);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
@@ -957,7 +904,6 @@ function CommandPaletteInner({
|
||||
onMouseMove={() => setCurrentCommand(command)}
|
||||
showShortcut={!app.device.viewport.isMobile}
|
||||
appState={uiAppState}
|
||||
size={category === "Library" ? "large" : "small"}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
@@ -973,20 +919,6 @@ function CommandPaletteInner({
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
const LibraryItemIcon = ({
|
||||
id,
|
||||
elements,
|
||||
}: {
|
||||
id: LibraryItem["id"] | null;
|
||||
elements: LibraryItem["elements"] | undefined;
|
||||
}) => {
|
||||
const ref = useRef<HTMLDivElement | null>(null);
|
||||
const { svgCache } = useLibraryCache();
|
||||
|
||||
useLibraryItemSvg(id, elements, svgCache, ref);
|
||||
|
||||
return <div className="library-item-icon" ref={ref} />;
|
||||
};
|
||||
|
||||
const CommandItem = ({
|
||||
command,
|
||||
@@ -996,7 +928,6 @@ const CommandItem = ({
|
||||
onClick,
|
||||
showShortcut,
|
||||
appState,
|
||||
size = "small",
|
||||
}: {
|
||||
command: CommandPaletteItem;
|
||||
isSelected: boolean;
|
||||
@@ -1005,7 +936,6 @@ const CommandItem = ({
|
||||
onClick: (event: React.MouseEvent) => void;
|
||||
showShortcut: boolean;
|
||||
appState: UIAppState;
|
||||
size?: "small" | "large";
|
||||
}) => {
|
||||
const noop = () => {};
|
||||
|
||||
@@ -1014,7 +944,6 @@ const CommandItem = ({
|
||||
className={clsx("command-item", {
|
||||
"item-selected": isSelected,
|
||||
"item-disabled": disabled,
|
||||
"command-item-large": size === "large",
|
||||
})}
|
||||
ref={(ref) => {
|
||||
if (isSelected && !disabled) {
|
||||
@@ -1030,8 +959,6 @@ const CommandItem = ({
|
||||
<div className="name">
|
||||
{command.icon && (
|
||||
<InlineIcon
|
||||
className="icon"
|
||||
size="var(--icon-size, 1rem)"
|
||||
icon={
|
||||
typeof command.icon === "function"
|
||||
? command.icon(appState)
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
@import "../css/variables.module.scss";
|
||||
|
||||
.excalidraw {
|
||||
.context-menu-popover {
|
||||
z-index: var(--zIndex-ui-context-menu);
|
||||
}
|
||||
|
||||
.context-menu {
|
||||
position: relative;
|
||||
border-radius: 4px;
|
||||
|
||||
@@ -64,7 +64,6 @@ export const ContextMenu = React.memo(
|
||||
offsetTop={appState.offsetTop}
|
||||
viewportWidth={appState.width}
|
||||
viewportHeight={appState.height}
|
||||
className="context-menu-popover"
|
||||
>
|
||||
<ul
|
||||
className="context-menu"
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
.excalidraw {
|
||||
.ExcalidrawLogo {
|
||||
--logo-icon--mobile: 1rem;
|
||||
--logo-text--mobile: 0.75rem;
|
||||
|
||||
--logo-icon--xs: 2rem;
|
||||
--logo-text--xs: 1.5rem;
|
||||
|
||||
@@ -33,17 +30,6 @@
|
||||
color: var(--color-logo-text);
|
||||
}
|
||||
|
||||
&.is-mobile {
|
||||
.ExcalidrawLogo-icon {
|
||||
height: var(--logo-icon--mobile);
|
||||
}
|
||||
|
||||
.ExcalidrawLogo-text {
|
||||
height: var(--logo-text--mobile);
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.is-xs {
|
||||
.ExcalidrawLogo-icon {
|
||||
height: var(--logo-icon--xs);
|
||||
|
||||
@@ -41,7 +41,7 @@ const LogoText = () => (
|
||||
</svg>
|
||||
);
|
||||
|
||||
type LogoSize = "xs" | "small" | "normal" | "large" | "custom" | "mobile";
|
||||
type LogoSize = "xs" | "small" | "normal" | "large" | "custom";
|
||||
|
||||
interface LogoProps {
|
||||
size?: LogoSize;
|
||||
|
||||
@@ -11,10 +11,5 @@
|
||||
2rem + 4 * var(--default-button-size)
|
||||
); // 4 gaps + 4 buttons
|
||||
}
|
||||
|
||||
&--compact {
|
||||
display: block;
|
||||
grid-template-columns: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
import clsx from "clsx";
|
||||
import React, { useCallback, useMemo } from "react";
|
||||
|
||||
import { FONT_FAMILY } from "@excalidraw/common";
|
||||
@@ -59,7 +58,6 @@ interface FontPickerProps {
|
||||
onHover: (fontFamily: FontFamilyValues) => void;
|
||||
onLeave: () => void;
|
||||
onPopupChange: (open: boolean) => void;
|
||||
compactMode?: boolean;
|
||||
}
|
||||
|
||||
export const FontPicker = React.memo(
|
||||
@@ -71,7 +69,6 @@ export const FontPicker = React.memo(
|
||||
onHover,
|
||||
onLeave,
|
||||
onPopupChange,
|
||||
compactMode = false,
|
||||
}: FontPickerProps) => {
|
||||
const defaultFonts = useMemo(() => DEFAULT_FONTS, []);
|
||||
const onSelectCallback = useCallback(
|
||||
@@ -84,30 +81,18 @@ export const FontPicker = React.memo(
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
className={clsx("FontPicker__container", {
|
||||
"FontPicker__container--compact": compactMode,
|
||||
})}
|
||||
>
|
||||
{!compactMode && (
|
||||
<div className="buttonList">
|
||||
<RadioSelection<FontFamilyValues | false>
|
||||
type="button"
|
||||
options={defaultFonts}
|
||||
value={selectedFontFamily}
|
||||
onClick={onSelectCallback}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{!compactMode && <ButtonSeparator />}
|
||||
<Popover.Root open={isOpened} onOpenChange={onPopupChange}>
|
||||
<FontPickerTrigger
|
||||
selectedFontFamily={selectedFontFamily}
|
||||
isOpened={isOpened}
|
||||
compactMode={compactMode}
|
||||
<div role="dialog" aria-modal="true" className="FontPicker__container">
|
||||
<div className="buttonList">
|
||||
<RadioSelection<FontFamilyValues | false>
|
||||
type="button"
|
||||
options={defaultFonts}
|
||||
value={selectedFontFamily}
|
||||
onClick={onSelectCallback}
|
||||
/>
|
||||
</div>
|
||||
<ButtonSeparator />
|
||||
<Popover.Root open={isOpened} onOpenChange={onPopupChange}>
|
||||
<FontPickerTrigger selectedFontFamily={selectedFontFamily} />
|
||||
{isOpened && (
|
||||
<FontPickerList
|
||||
selectedFontFamily={selectedFontFamily}
|
||||
|
||||
@@ -90,8 +90,7 @@ export const FontPickerList = React.memo(
|
||||
onClose,
|
||||
}: FontPickerListProps) => {
|
||||
const { container } = useExcalidrawContainer();
|
||||
const app = useApp();
|
||||
const { fonts } = app;
|
||||
const { fonts } = useApp();
|
||||
const { showDeprecatedFonts } = useAppProps();
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
@@ -188,42 +187,6 @@ export const FontPickerList = React.memo(
|
||||
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>>(
|
||||
(event) => {
|
||||
const handled = fontPickerKeyHandler({
|
||||
@@ -231,7 +194,7 @@ export const FontPickerList = React.memo(
|
||||
inputRef,
|
||||
hoveredFont,
|
||||
filteredFonts,
|
||||
onSelect: wrappedOnSelect,
|
||||
onSelect,
|
||||
onHover,
|
||||
onClose,
|
||||
});
|
||||
@@ -241,7 +204,7 @@ export const FontPickerList = React.memo(
|
||||
event.stopPropagation();
|
||||
}
|
||||
},
|
||||
[hoveredFont, filteredFonts, wrappedOnSelect, onHover, onClose],
|
||||
[hoveredFont, filteredFonts, onSelect, onHover, onClose],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -277,7 +240,7 @@ export const FontPickerList = React.memo(
|
||||
// allow to tab between search and selected font
|
||||
tabIndex={font.value === selectedFontFamily ? 0 : -1}
|
||||
onClick={(e) => {
|
||||
wrappedOnSelect(Number(e.currentTarget.value));
|
||||
onSelect(Number(e.currentTarget.value));
|
||||
}}
|
||||
onMouseMove={() => {
|
||||
if (hoveredFont?.value !== font.value) {
|
||||
@@ -319,32 +282,15 @@ export const FontPickerList = React.memo(
|
||||
className="properties-content"
|
||||
container={container}
|
||||
style={{ width: "15rem" }}
|
||||
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);
|
||||
}
|
||||
}}
|
||||
onClose={onClose}
|
||||
onPointerLeave={onLeave}
|
||||
onKeyDown={onKeyDown}
|
||||
preventAutoFocusOnTouch={!!app.state.editingTextElement}
|
||||
>
|
||||
{app.state.stylesPanelMode === "full" && (
|
||||
<QuickSearch
|
||||
ref={inputRef}
|
||||
placeholder={t("quickSearch.placeholder")}
|
||||
onChange={debounce(setSearchTerm, 20)}
|
||||
/>
|
||||
)}
|
||||
<QuickSearch
|
||||
ref={inputRef}
|
||||
placeholder={t("quickSearch.placeholder")}
|
||||
onChange={debounce(setSearchTerm, 20)}
|
||||
/>
|
||||
<ScrollableList
|
||||
className="dropdown-menu fonts manual-hover"
|
||||
placeholder={t("fontList.empty")}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import * as Popover from "@radix-ui/react-popover";
|
||||
|
||||
import { MOBILE_ACTION_BUTTON_BG } from "@excalidraw/common";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import type { FontFamilyValues } from "@excalidraw/element/types";
|
||||
|
||||
@@ -8,49 +7,33 @@ import { t } from "../../i18n";
|
||||
import { ButtonIcon } from "../ButtonIcon";
|
||||
import { TextIcon } from "../icons";
|
||||
|
||||
import { useExcalidrawSetAppState } from "../App";
|
||||
import { isDefaultFont } from "./FontPicker";
|
||||
|
||||
interface FontPickerTriggerProps {
|
||||
selectedFontFamily: FontFamilyValues | null;
|
||||
isOpened?: boolean;
|
||||
compactMode?: boolean;
|
||||
}
|
||||
|
||||
export const FontPickerTrigger = ({
|
||||
selectedFontFamily,
|
||||
isOpened = false,
|
||||
compactMode = false,
|
||||
}: FontPickerTriggerProps) => {
|
||||
const setAppState = useExcalidrawSetAppState();
|
||||
|
||||
const compactStyle = compactMode
|
||||
? {
|
||||
...MOBILE_ACTION_BUTTON_BG,
|
||||
width: "2rem",
|
||||
height: "2rem",
|
||||
}
|
||||
: {};
|
||||
const isTriggerActive = useMemo(
|
||||
() => Boolean(selectedFontFamily && !isDefaultFont(selectedFontFamily)),
|
||||
[selectedFontFamily],
|
||||
);
|
||||
|
||||
return (
|
||||
<Popover.Trigger asChild>
|
||||
<div data-openpopup="fontFamily" className="properties-trigger">
|
||||
{/* Empty div as trigger so it's stretched 100% due to different button sizes */}
|
||||
<div>
|
||||
<ButtonIcon
|
||||
standalone
|
||||
icon={TextIcon}
|
||||
title={t("labels.showFonts")}
|
||||
className="properties-trigger"
|
||||
testId={"font-family-show-fonts"}
|
||||
active={isOpened}
|
||||
onClick={() => {
|
||||
setAppState((appState) => ({
|
||||
openPopup:
|
||||
appState.openPopup === "fontFamily" ? null : appState.openPopup,
|
||||
}));
|
||||
}}
|
||||
style={{
|
||||
border: "none",
|
||||
...compactStyle,
|
||||
}}
|
||||
active={isTriggerActive}
|
||||
// no-op
|
||||
onClick={() => {}}
|
||||
/>
|
||||
</div>
|
||||
</Popover.Trigger>
|
||||
|
||||
@@ -18,7 +18,7 @@ type LockIconProps = {
|
||||
export const HandButton = (props: LockIconProps) => {
|
||||
return (
|
||||
<ToolButton
|
||||
className={clsx("Shape", { fillable: false, active: props.checked })}
|
||||
className={clsx("Shape", { fillable: false })}
|
||||
type="radio"
|
||||
icon={handIcon}
|
||||
name="editor-current-shape"
|
||||
|
||||
@@ -2,12 +2,11 @@ import React from "react";
|
||||
|
||||
import { isDarwin, isFirefox, isWindows } from "@excalidraw/common";
|
||||
|
||||
import { KEYS } from "@excalidraw/common";
|
||||
import { KEYS, getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import { getShortcutFromShortcutName } from "../actions/shortcuts";
|
||||
import { probablySupportsClipboardBlob } from "../clipboard";
|
||||
import { t } from "../i18n";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
|
||||
import { Dialog } from "./Dialog";
|
||||
import { ExternalLinkIcon, GithubIcon, youtubeIcon } from "./icons";
|
||||
|
||||
@@ -28,24 +28,11 @@ $wide-viewport-width: 1000px;
|
||||
> span {
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
kbd {
|
||||
display: inline-block;
|
||||
margin: 0 1px;
|
||||
font-family: monospace;
|
||||
border: 1px solid var(--color-gray-40);
|
||||
border-radius: 4px;
|
||||
padding: 1px 3px;
|
||||
font-size: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
&.theme--dark {
|
||||
.HintViewer {
|
||||
color: var(--color-gray-60);
|
||||
kbd {
|
||||
border-color: var(--color-gray-60);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@ import {
|
||||
isTextElement,
|
||||
} from "@excalidraw/element";
|
||||
|
||||
import { getShortcutKey } from "@excalidraw/common";
|
||||
|
||||
import { isNodeInFlowchart } from "@excalidraw/element";
|
||||
|
||||
import { t } from "../i18n";
|
||||
import { getShortcutKey } from "../shortcut";
|
||||
import { isEraserActive } from "../appState";
|
||||
import { isGridModeEnabled } from "../snapping";
|
||||
|
||||
@@ -27,11 +28,6 @@ interface HintViewerProps {
|
||||
app: AppClassProperties;
|
||||
}
|
||||
|
||||
const getTaggedShortcutKey = (key: string | string[]) =>
|
||||
Array.isArray(key)
|
||||
? `<kbd>${key.map(getShortcutKey).join(" + ")}</kbd>`
|
||||
: `<kbd>${getShortcutKey(key)}</kbd>`;
|
||||
|
||||
const getHints = ({
|
||||
appState,
|
||||
isMobile,
|
||||
@@ -46,9 +42,7 @@ const getHints = ({
|
||||
appState.openSidebar.tab === CANVAS_SEARCH_TAB &&
|
||||
appState.searchMatches?.matches.length
|
||||
) {
|
||||
return t("hints.dismissSearch", {
|
||||
shortcut: getTaggedShortcutKey("Escape"),
|
||||
});
|
||||
return t("hints.dismissSearch");
|
||||
}
|
||||
|
||||
if (appState.openSidebar && !device.editor.canFitSidebar) {
|
||||
@@ -56,21 +50,14 @@ const getHints = ({
|
||||
}
|
||||
|
||||
if (isEraserActive(appState)) {
|
||||
return t("hints.eraserRevert", {
|
||||
shortcut: getTaggedShortcutKey("Alt"),
|
||||
});
|
||||
return t("hints.eraserRevert");
|
||||
}
|
||||
if (activeTool.type === "arrow" || activeTool.type === "line") {
|
||||
if (multiMode) {
|
||||
return t("hints.linearElementMulti", {
|
||||
shortcut_1: getTaggedShortcutKey("Escape"),
|
||||
shortcut_2: getTaggedShortcutKey("Enter"),
|
||||
});
|
||||
return t("hints.linearElementMulti");
|
||||
}
|
||||
if (activeTool.type === "arrow") {
|
||||
return t("hints.arrowTool", {
|
||||
shortcut: getTaggedShortcutKey("A"),
|
||||
});
|
||||
return t("hints.arrowTool", { arrowShortcut: getShortcutKey("A") });
|
||||
}
|
||||
return t("hints.linearElement");
|
||||
}
|
||||
@@ -96,51 +83,31 @@ const getHints = ({
|
||||
) {
|
||||
const targetElement = selectedElements[0];
|
||||
if (isLinearElement(targetElement) && targetElement.points.length === 2) {
|
||||
return t("hints.lockAngle", {
|
||||
shortcut: getTaggedShortcutKey("Shift"),
|
||||
});
|
||||
return t("hints.lockAngle");
|
||||
}
|
||||
return isImageElement(targetElement)
|
||||
? t("hints.resizeImage", {
|
||||
shortcut_1: getTaggedShortcutKey("Shift"),
|
||||
shortcut_2: getTaggedShortcutKey("Alt"),
|
||||
})
|
||||
: t("hints.resize", {
|
||||
shortcut_1: getTaggedShortcutKey("Shift"),
|
||||
shortcut_2: getTaggedShortcutKey("Alt"),
|
||||
});
|
||||
? t("hints.resizeImage")
|
||||
: t("hints.resize");
|
||||
}
|
||||
|
||||
if (isRotating && lastPointerDownWith === "mouse") {
|
||||
return t("hints.rotate", {
|
||||
shortcut: getTaggedShortcutKey("Shift"),
|
||||
});
|
||||
return t("hints.rotate");
|
||||
}
|
||||
|
||||
if (selectedElements.length === 1 && isTextElement(selectedElements[0])) {
|
||||
return t("hints.text_selected", {
|
||||
shortcut: getTaggedShortcutKey("Enter"),
|
||||
});
|
||||
return t("hints.text_selected");
|
||||
}
|
||||
|
||||
if (appState.editingTextElement) {
|
||||
return t("hints.text_editing", {
|
||||
shortcut_1: getTaggedShortcutKey("Escape"),
|
||||
shortcut_2: getTaggedShortcutKey(["CtrlOrCmd", "Enter"]),
|
||||
});
|
||||
return t("hints.text_editing");
|
||||
}
|
||||
|
||||
if (appState.croppingElementId) {
|
||||
return t("hints.leaveCropEditor", {
|
||||
shortcut_1: getTaggedShortcutKey("Enter"),
|
||||
shortcut_2: getTaggedShortcutKey("Escape"),
|
||||
});
|
||||
return t("hints.leaveCropEditor");
|
||||
}
|
||||
|
||||
if (selectedElements.length === 1 && isImageElement(selectedElements[0])) {
|
||||
return t("hints.enterCropEditor", {
|
||||
shortcut: getTaggedShortcutKey("Enter"),
|
||||
});
|
||||
return t("hints.enterCropEditor");
|
||||
}
|
||||
|
||||
if (activeTool.type === "selection") {
|
||||
@@ -150,57 +117,33 @@ const getHints = ({
|
||||
!appState.editingTextElement &&
|
||||
!appState.selectedLinearElement?.isEditing
|
||||
) {
|
||||
return t("hints.deepBoxSelect", {
|
||||
shortcut: getTaggedShortcutKey("CtrlOrCmd"),
|
||||
});
|
||||
return [t("hints.deepBoxSelect")];
|
||||
}
|
||||
|
||||
if (isGridModeEnabled(app) && appState.selectedElementsAreBeingDragged) {
|
||||
return t("hints.disableSnapping", {
|
||||
shortcut: getTaggedShortcutKey("CtrlOrCmd"),
|
||||
});
|
||||
return t("hints.disableSnapping");
|
||||
}
|
||||
|
||||
if (!selectedElements.length && !isMobile) {
|
||||
return t("hints.canvasPanning", {
|
||||
shortcut_1: getTaggedShortcutKey(t("keys.mmb")),
|
||||
shortcut_2: getTaggedShortcutKey("Space"),
|
||||
});
|
||||
return [t("hints.canvasPanning")];
|
||||
}
|
||||
|
||||
if (selectedElements.length === 1) {
|
||||
if (isLinearElement(selectedElements[0])) {
|
||||
if (appState.selectedLinearElement?.isEditing) {
|
||||
return appState.selectedLinearElement.selectedPointsIndices
|
||||
? t("hints.lineEditor_pointSelected", {
|
||||
shortcut_1: getTaggedShortcutKey("Delete"),
|
||||
shortcut_2: getTaggedShortcutKey(["CtrlOrCmd", "D"]),
|
||||
})
|
||||
: t("hints.lineEditor_nothingSelected", {
|
||||
shortcut_1: getTaggedShortcutKey("Shift"),
|
||||
shortcut_2: getTaggedShortcutKey("Alt"),
|
||||
});
|
||||
? t("hints.lineEditor_pointSelected")
|
||||
: t("hints.lineEditor_nothingSelected");
|
||||
}
|
||||
return isLineElement(selectedElements[0])
|
||||
? t("hints.lineEditor_line_info", {
|
||||
shortcut: getTaggedShortcutKey("Enter"),
|
||||
})
|
||||
: t("hints.lineEditor_info", {
|
||||
shortcut_1: getTaggedShortcutKey("CtrlOrCmd"),
|
||||
shortcut_2: getTaggedShortcutKey(["CtrlOrCmd", "Enter"]),
|
||||
});
|
||||
? t("hints.lineEditor_line_info")
|
||||
: t("hints.lineEditor_info");
|
||||
}
|
||||
if (
|
||||
!appState.newElement &&
|
||||
!appState.selectedElementsAreBeingDragged &&
|
||||
isTextBindableContainer(selectedElements[0])
|
||||
) {
|
||||
const bindTextToElement = t("hints.bindTextToElement", {
|
||||
shortcut: getTaggedShortcutKey("Enter"),
|
||||
});
|
||||
const createFlowchart = t("hints.createFlowchart", {
|
||||
shortcut: getTaggedShortcutKey(["CtrlOrCmd", "↑↓"]),
|
||||
});
|
||||
if (isFlowchartNodeElement(selectedElements[0])) {
|
||||
if (
|
||||
isNodeInFlowchart(
|
||||
@@ -208,13 +151,13 @@ const getHints = ({
|
||||
app.scene.getNonDeletedElementsMap(),
|
||||
)
|
||||
) {
|
||||
return [bindTextToElement, createFlowchart];
|
||||
return [t("hints.bindTextToElement"), t("hints.createFlowchart")];
|
||||
}
|
||||
|
||||
return [bindTextToElement, createFlowchart];
|
||||
return [t("hints.bindTextToElement"), t("hints.createFlowchart")];
|
||||
}
|
||||
|
||||
return bindTextToElement;
|
||||
return t("hints.bindTextToElement");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -240,21 +183,16 @@ export const HintViewer = ({
|
||||
}
|
||||
|
||||
const hint = Array.isArray(hints)
|
||||
? hints.map((hint) => hint.replace(/\. ?$/, "")).join(", ")
|
||||
: hints;
|
||||
|
||||
const hintJSX = hint.split(/(<kbd>[^<]+<\/kbd>)/g).map((part, index) => {
|
||||
if (index % 2 === 1) {
|
||||
const shortcutMatch =
|
||||
part[0] === "<" && part.match(/^<kbd>([^<]+)<\/kbd>$/);
|
||||
return <kbd key={index}>{shortcutMatch ? shortcutMatch[1] : part}</kbd>;
|
||||
}
|
||||
return part;
|
||||
});
|
||||
? hints
|
||||
.map((hint) => {
|
||||
return getShortcutKey(hint).replace(/\. ?$/, "");
|
||||
})
|
||||
.join(". ")
|
||||
: getShortcutKey(hints);
|
||||
|
||||
return (
|
||||
<div className="HintViewer">
|
||||
<span>{hintJSX}</span>
|
||||
<span>{hint}</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import { atom, useAtom } from "../editor-jotai";
|
||||
import { getLanguage, t } from "../i18n";
|
||||
|
||||
import Collapsible from "./Stats/Collapsible";
|
||||
import { useDevice, useExcalidrawContainer } from "./App";
|
||||
import { useDevice } from "./App";
|
||||
|
||||
import "./IconPicker.scss";
|
||||
|
||||
@@ -39,7 +39,6 @@ function Picker<T>({
|
||||
numberOfOptionsToAlwaysShow?: number;
|
||||
}) {
|
||||
const device = useDevice();
|
||||
const { container } = useExcalidrawContainer();
|
||||
|
||||
const handleKeyDown = (event: React.KeyboardEvent) => {
|
||||
const pressedOption = options.find(
|
||||
@@ -153,16 +152,17 @@ function Picker<T>({
|
||||
);
|
||||
};
|
||||
|
||||
const isMobile = device.editor.isMobile;
|
||||
|
||||
return (
|
||||
<Popover.Content
|
||||
side={isMobile ? "right" : "bottom"}
|
||||
side={
|
||||
device.editor.isMobile && !device.viewport.isLandscape
|
||||
? "top"
|
||||
: "bottom"
|
||||
}
|
||||
align="start"
|
||||
sideOffset={isMobile ? 8 : 12}
|
||||
style={{ zIndex: "var(--zIndex-ui-styles-popup)" }}
|
||||
sideOffset={12}
|
||||
style={{ zIndex: "var(--zIndex-popup)" }}
|
||||
onKeyDown={handleKeyDown}
|
||||
collisionBoundary={container ?? undefined}
|
||||
>
|
||||
<div
|
||||
className={`picker`}
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
export const InlineIcon = ({
|
||||
className,
|
||||
icon,
|
||||
size = "1em",
|
||||
}: {
|
||||
className?: string;
|
||||
icon: React.ReactNode;
|
||||
size?: string;
|
||||
}) => {
|
||||
export const InlineIcon = ({ icon }: { icon: React.ReactNode }) => {
|
||||
return (
|
||||
<span
|
||||
className={className}
|
||||
style={{
|
||||
width: size,
|
||||
height: "100%",
|
||||
width: "1em",
|
||||
margin: "0 0.5ex 0 0.5ex",
|
||||
display: "inline-flex",
|
||||
display: "inline-block",
|
||||
lineHeight: 0,
|
||||
verticalAlign: "middle",
|
||||
flex: "0 0 auto",
|
||||
|
||||
@@ -24,10 +24,6 @@
|
||||
gap: 0.75rem;
|
||||
pointer-events: none !important;
|
||||
|
||||
&--compact {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
& > * {
|
||||
pointer-events: var(--ui-pointerEvents);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import React from "react";
|
||||
import {
|
||||
CLASSES,
|
||||
DEFAULT_SIDEBAR,
|
||||
MQ_MIN_WIDTH_DESKTOP,
|
||||
TOOL_TYPE,
|
||||
arrayToMap,
|
||||
capitalizeString,
|
||||
@@ -29,11 +28,7 @@ import { useAtom, useAtomValue } from "../editor-jotai";
|
||||
import { t } from "../i18n";
|
||||
import { calculateScrollCenter } from "../scene";
|
||||
|
||||
import {
|
||||
SelectedShapeActions,
|
||||
ShapesSwitcher,
|
||||
CompactShapeActions,
|
||||
} from "./Actions";
|
||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
||||
import { LoadingMessage } from "./LoadingMessage";
|
||||
import { LockButton } from "./LockButton";
|
||||
import { MobileMenu } from "./MobileMenu";
|
||||
@@ -91,7 +86,6 @@ interface LayerUIProps {
|
||||
onPenModeToggle: AppClassProperties["togglePenMode"];
|
||||
showExitZenModeBtn: boolean;
|
||||
langCode: Language["code"];
|
||||
renderTopLeftUI?: ExcalidrawProps["renderTopLeftUI"];
|
||||
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
|
||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
||||
UIOptions: AppProps["UIOptions"];
|
||||
@@ -150,7 +144,6 @@ const LayerUI = ({
|
||||
onHandToolToggle,
|
||||
onPenModeToggle,
|
||||
showExitZenModeBtn,
|
||||
renderTopLeftUI,
|
||||
renderTopRightUI,
|
||||
renderCustomStats,
|
||||
UIOptions,
|
||||
@@ -164,25 +157,6 @@ const LayerUI = ({
|
||||
const device = useDevice();
|
||||
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 [eyeDropperState, setEyeDropperState] = useAtom(activeEyeDropperAtom);
|
||||
@@ -235,55 +209,31 @@ const LayerUI = ({
|
||||
</div>
|
||||
);
|
||||
|
||||
const renderSelectedShapeActions = () => {
|
||||
const isCompactMode = appState.stylesPanelMode === "compact";
|
||||
|
||||
return (
|
||||
<Section
|
||||
heading="selectedShapeActions"
|
||||
className={clsx("selected-shape-actions zen-mode-transition", {
|
||||
"transition-left": appState.zenModeEnabled,
|
||||
})}
|
||||
const renderSelectedShapeActions = () => (
|
||||
<Section
|
||||
heading="selectedShapeActions"
|
||||
className={clsx("selected-shape-actions zen-mode-transition", {
|
||||
"transition-left": appState.zenModeEnabled,
|
||||
})}
|
||||
>
|
||||
<Island
|
||||
className={CLASSES.SHAPE_ACTIONS_MENU}
|
||||
padding={2}
|
||||
style={{
|
||||
// we want to make sure this doesn't overflow so subtracting the
|
||||
// approximate height of hamburgerMenu + footer
|
||||
maxHeight: `${appState.height - 166}px`,
|
||||
}}
|
||||
>
|
||||
{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
|
||||
className={CLASSES.SHAPE_ACTIONS_MENU}
|
||||
padding={2}
|
||||
style={{
|
||||
// we want to make sure this doesn't overflow so subtracting the
|
||||
// approximate height of hamburgerMenu + footer
|
||||
maxHeight: `${appState.height - 166}px`,
|
||||
}}
|
||||
>
|
||||
<SelectedShapeActions
|
||||
appState={appState}
|
||||
elementsMap={app.scene.getNonDeletedElementsMap()}
|
||||
renderAction={actionManager.renderAction}
|
||||
app={app}
|
||||
/>
|
||||
</Island>
|
||||
)}
|
||||
</Section>
|
||||
);
|
||||
};
|
||||
<SelectedShapeActions
|
||||
appState={appState}
|
||||
elementsMap={app.scene.getNonDeletedElementsMap()}
|
||||
renderAction={actionManager.renderAction}
|
||||
app={app}
|
||||
/>
|
||||
</Island>
|
||||
</Section>
|
||||
);
|
||||
|
||||
const renderFixedSideContainer = () => {
|
||||
const shouldRenderSelectedShapeActions = showSelectedShapeActions(
|
||||
@@ -300,19 +250,9 @@ const LayerUI = ({
|
||||
return (
|
||||
<FixedSideContainer side="top">
|
||||
<div className="App-menu App-menu_top">
|
||||
<Stack.Col
|
||||
gap={spacing.menuTopGap}
|
||||
className={clsx("App-menu_top__left")}
|
||||
>
|
||||
<Stack.Col gap={6} className={clsx("App-menu_top__left")}>
|
||||
{renderCanvasActions()}
|
||||
<div
|
||||
className={clsx("selected-shape-actions-container", {
|
||||
"selected-shape-actions-container--compact":
|
||||
appState.stylesPanelMode === "compact",
|
||||
})}
|
||||
>
|
||||
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
||||
</div>
|
||||
{shouldRenderSelectedShapeActions && renderSelectedShapeActions()}
|
||||
</Stack.Col>
|
||||
{!appState.viewModeEnabled &&
|
||||
appState.openDialog?.name !== "elementLinkSelector" && (
|
||||
@@ -322,19 +262,17 @@ const LayerUI = ({
|
||||
{renderWelcomeScreen && (
|
||||
<tunnels.WelcomeScreenToolbarHintTunnel.Out />
|
||||
)}
|
||||
<Stack.Col gap={spacing.toolbarColGap} align="start">
|
||||
<Stack.Col gap={4} align="start">
|
||||
<Stack.Row
|
||||
gap={spacing.toolbarRowGap}
|
||||
gap={1}
|
||||
className={clsx("App-toolbar-container", {
|
||||
"zen-mode": appState.zenModeEnabled,
|
||||
})}
|
||||
>
|
||||
<Island
|
||||
padding={spacing.islandPadding}
|
||||
padding={1}
|
||||
className={clsx("App-toolbar", {
|
||||
"zen-mode": appState.zenModeEnabled,
|
||||
"App-toolbar--compact":
|
||||
appState.stylesPanelMode === "compact",
|
||||
})}
|
||||
>
|
||||
<HintViewer
|
||||
@@ -344,7 +282,7 @@ const LayerUI = ({
|
||||
app={app}
|
||||
/>
|
||||
{heading}
|
||||
<Stack.Row gap={spacing.toolbarInnerRowGap}>
|
||||
<Stack.Row gap={1}>
|
||||
<PenModeButton
|
||||
zenModeEnabled={appState.zenModeEnabled}
|
||||
checked={appState.penMode}
|
||||
@@ -368,7 +306,7 @@ const LayerUI = ({
|
||||
/>
|
||||
|
||||
<ShapesSwitcher
|
||||
setAppState={setAppState}
|
||||
appState={appState}
|
||||
activeTool={appState.activeTool}
|
||||
UIOptions={UIOptions}
|
||||
app={app}
|
||||
@@ -378,7 +316,7 @@ const LayerUI = ({
|
||||
{isCollaborating && (
|
||||
<Island
|
||||
style={{
|
||||
marginLeft: spacing.collabMarginLeft,
|
||||
marginLeft: 8,
|
||||
alignSelf: "center",
|
||||
height: "fit-content",
|
||||
}}
|
||||
@@ -406,8 +344,6 @@ const LayerUI = ({
|
||||
"layer-ui__wrapper__top-right zen-mode-transition",
|
||||
{
|
||||
"transition-right": appState.zenModeEnabled,
|
||||
"layer-ui__wrapper__top-right--compact":
|
||||
appState.stylesPanelMode === "compact",
|
||||
},
|
||||
)}
|
||||
>
|
||||
@@ -482,9 +418,7 @@ const LayerUI = ({
|
||||
}}
|
||||
tab={DEFAULT_SIDEBAR.defaultTab}
|
||||
>
|
||||
{appState.stylesPanelMode === "full" &&
|
||||
appState.width >= MQ_MIN_WIDTH_DESKTOP &&
|
||||
t("toolBar.library")}
|
||||
{t("toolBar.library")}
|
||||
</DefaultSidebar.Trigger>
|
||||
<DefaultOverwriteConfirmDialog />
|
||||
{appState.openDialog?.name === "ttd" && <TTDDialog __fallback />}
|
||||
@@ -584,11 +518,13 @@ const LayerUI = ({
|
||||
renderJSONExportDialog={renderJSONExportDialog}
|
||||
renderImageExportDialog={renderImageExportDialog}
|
||||
setAppState={setAppState}
|
||||
onLockToggle={onLockToggle}
|
||||
onHandToolToggle={onHandToolToggle}
|
||||
onPenModeToggle={onPenModeToggle}
|
||||
renderTopLeftUI={renderTopLeftUI}
|
||||
renderTopRightUI={renderTopRightUI}
|
||||
renderCustomStats={renderCustomStats}
|
||||
renderSidebars={renderSidebars}
|
||||
device={device}
|
||||
renderWelcomeScreen={renderWelcomeScreen}
|
||||
UIOptions={UIOptions}
|
||||
/>
|
||||
|
||||
@@ -133,10 +133,15 @@
|
||||
}
|
||||
|
||||
.layer-ui__library .library-menu-dropdown-container {
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
|
||||
&--in-heading {
|
||||
margin-left: auto;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
top: 1rem;
|
||||
right: 0.75rem;
|
||||
z-index: 1;
|
||||
|
||||
.dropdown-menu {
|
||||
top: 100%;
|
||||
}
|
||||
|
||||
@@ -11,11 +11,6 @@ import {
|
||||
LIBRARY_DISABLED_TYPES,
|
||||
randomId,
|
||||
isShallowEqual,
|
||||
KEYS,
|
||||
isWritableElement,
|
||||
addEventListener,
|
||||
EVENT,
|
||||
CLASSES,
|
||||
} from "@excalidraw/common";
|
||||
|
||||
import type {
|
||||
@@ -271,52 +266,11 @@ export const LibraryMenu = memo(() => {
|
||||
const memoizedLibrary = useMemo(() => app.library, [app.library]);
|
||||
const pendingElements = usePendingElementsMemo(appState, app);
|
||||
|
||||
useEffect(() => {
|
||||
return addEventListener(
|
||||
document,
|
||||
EVENT.KEYDOWN,
|
||||
(event) => {
|
||||
if (event.key === KEYS.ESCAPE && event.target instanceof HTMLElement) {
|
||||
const target = event.target;
|
||||
if (target.closest(`.${CLASSES.SIDEBAR}`)) {
|
||||
// stop propagation so that we don't prevent it downstream
|
||||
// (default browser behavior is to clear search input on ESC)
|
||||
if (selectedItems.length > 0) {
|
||||
event.stopPropagation();
|
||||
setSelectedItems([]);
|
||||
} else if (
|
||||
isWritableElement(target) &&
|
||||
target instanceof HTMLInputElement &&
|
||||
!target.value
|
||||
) {
|
||||
event.stopPropagation();
|
||||
// if search input empty -> close library
|
||||
// (maybe not a good idea?)
|
||||
setAppState({ openSidebar: null });
|
||||
app.focusContainer();
|
||||
}
|
||||
} else if (selectedItems.length > 0) {
|
||||
const { x, y } = app.lastViewportPosition;
|
||||
const elementUnderCursor = document.elementFromPoint(x, y);
|
||||
// also deselect elements if sidebar doesn't have focus but the
|
||||
// cursor is over it
|
||||
if (elementUnderCursor?.closest(`.${CLASSES.SIDEBAR}`)) {
|
||||
event.stopPropagation();
|
||||
setSelectedItems([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ capture: true },
|
||||
);
|
||||
}, [selectedItems, setAppState, app]);
|
||||
|
||||
const onInsertLibraryItems = useCallback(
|
||||
(libraryItems: LibraryItems) => {
|
||||
onInsertElements(distributeLibraryItemsOnSquareGrid(libraryItems));
|
||||
app.focusContainer();
|
||||
},
|
||||
[onInsertElements, app],
|
||||
[onInsertElements],
|
||||
);
|
||||
|
||||
const deselectItems = useCallback(() => {
|
||||
|
||||
@@ -220,6 +220,14 @@ export const LibraryDropdownMenuButton: React.FC<{
|
||||
{t("buttons.export")}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
{!!items.length && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => setShowRemoveLibAlert(true)}
|
||||
icon={TrashIcon}
|
||||
>
|
||||
{resetLabel}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
{itemsSelected && (
|
||||
<DropdownMenu.Item
|
||||
icon={publishIcon}
|
||||
@@ -229,14 +237,6 @@ export const LibraryDropdownMenuButton: React.FC<{
|
||||
{t("buttons.publishLibrary")}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
{!!items.length && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => setShowRemoveLibAlert(true)}
|
||||
icon={TrashIcon}
|
||||
>
|
||||
{resetLabel}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
||||
@@ -1,42 +1,24 @@
|
||||
@import "open-color/open-color";
|
||||
|
||||
.excalidraw {
|
||||
--container-padding-y: 1rem;
|
||||
--container-padding-y: 1.5rem;
|
||||
--container-padding-x: 0.75rem;
|
||||
|
||||
.library-menu-items-header {
|
||||
display: flex;
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 0.5rem;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.library-menu-items__no-items {
|
||||
text-align: center;
|
||||
color: var(--color-gray-70);
|
||||
line-height: 1.5;
|
||||
font-size: 0.875rem;
|
||||
width: 100%;
|
||||
min-height: 55px;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&__label {
|
||||
color: var(--color-primary);
|
||||
font-weight: 700;
|
||||
font-size: 1.125rem;
|
||||
margin-bottom: 0.25rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
.library-menu-items__no-items__hint {
|
||||
color: var(--color-border-outline);
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
&.theme--dark {
|
||||
.library-menu-items__no-items {
|
||||
color: var(--color-gray-40);
|
||||
@@ -52,7 +34,7 @@
|
||||
overflow-y: auto;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
justify-content: flex-start;
|
||||
justify-content: center;
|
||||
margin: 0;
|
||||
|
||||
position: relative;
|
||||
@@ -69,45 +51,26 @@
|
||||
}
|
||||
|
||||
&__items {
|
||||
// so that spinner is relative-positioned to this container
|
||||
position: relative;
|
||||
|
||||
row-gap: 0.5rem;
|
||||
padding: 1rem 0 var(--container-padding-y) 0;
|
||||
padding: var(--container-padding-y) 0;
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
&__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1 1 auto;
|
||||
|
||||
color: var(--color-primary);
|
||||
font-size: 1.125rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 0.75rem;
|
||||
width: 100%;
|
||||
padding-right: 4rem; // due to dropdown button
|
||||
box-sizing: border-box;
|
||||
|
||||
&--excal {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
&__hint {
|
||||
margin-left: auto;
|
||||
font-size: 10px;
|
||||
color: var(--color-border-outline);
|
||||
font-weight: 400;
|
||||
|
||||
kbd {
|
||||
font-family: monospace;
|
||||
border: 1px solid var(--color-border-outline);
|
||||
border-radius: 4px;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&__grid {
|
||||
@@ -116,24 +79,6 @@
|
||||
grid-gap: 1rem;
|
||||
}
|
||||
|
||||
&__search {
|
||||
flex: 1 1 auto;
|
||||
margin: 0;
|
||||
|
||||
.ExcTextField__input {
|
||||
height: var(--lg-button-size);
|
||||
input {
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.hideCancelButton input::-webkit-search-cancel-button {
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.separator {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
|
||||
@@ -6,14 +6,11 @@ import React, {
|
||||
useState,
|
||||
} from "react";
|
||||
|
||||
import { MIME_TYPES, arrayToMap, nextAnimationFrame } from "@excalidraw/common";
|
||||
import { MIME_TYPES, arrayToMap } from "@excalidraw/common";
|
||||
|
||||
import { duplicateElements } from "@excalidraw/element";
|
||||
|
||||
import clsx from "clsx";
|
||||
|
||||
import { deburr } from "../deburr";
|
||||
|
||||
import { serializeLibraryAsJSON } from "../data/json";
|
||||
import { useLibraryCache } from "../hooks/useLibraryItemSvg";
|
||||
import { useScrollPosition } from "../hooks/useScrollPosition";
|
||||
import { t } from "../i18n";
|
||||
@@ -30,14 +27,6 @@ import Stack from "./Stack";
|
||||
|
||||
import "./LibraryMenuItems.scss";
|
||||
|
||||
import { TextField } from "./TextField";
|
||||
|
||||
import { useDevice } from "./App";
|
||||
|
||||
import { Button } from "./Button";
|
||||
|
||||
import type { ExcalidrawLibraryIds } from "../data/types";
|
||||
|
||||
import type {
|
||||
ExcalidrawProps,
|
||||
LibraryItem,
|
||||
@@ -75,7 +64,6 @@ export default function LibraryMenuItems({
|
||||
selectedItems: LibraryItem["id"][];
|
||||
onSelectItems: (id: LibraryItem["id"][]) => void;
|
||||
}) {
|
||||
const device = useDevice();
|
||||
const libraryContainerRef = useRef<HTMLDivElement>(null);
|
||||
const scrollPosition = useScrollPosition<HTMLDivElement>(libraryContainerRef);
|
||||
|
||||
@@ -87,30 +75,6 @@ export default function LibraryMenuItems({
|
||||
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const { svgCache } = useLibraryCache();
|
||||
const [lastSelectedItem, setLastSelectedItem] = useState<
|
||||
LibraryItem["id"] | null
|
||||
>(null);
|
||||
|
||||
const [searchInputValue, setSearchInputValue] = useState("");
|
||||
|
||||
const IS_LIBRARY_EMPTY = !libraryItems.length && !pendingElements.length;
|
||||
|
||||
const IS_SEARCHING = !IS_LIBRARY_EMPTY && !!searchInputValue.trim();
|
||||
|
||||
const filteredItems = useMemo(() => {
|
||||
const searchQuery = deburr(searchInputValue.trim().toLowerCase());
|
||||
if (!searchQuery) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return libraryItems.filter((item) => {
|
||||
const itemName = item.name || "";
|
||||
return (
|
||||
itemName.trim() && deburr(itemName.toLowerCase()).includes(searchQuery)
|
||||
);
|
||||
});
|
||||
}, [libraryItems, searchInputValue]);
|
||||
|
||||
const unpublishedItems = useMemo(
|
||||
() => libraryItems.filter((item) => item.status !== "published"),
|
||||
[libraryItems],
|
||||
@@ -121,10 +85,23 @@ export default function LibraryMenuItems({
|
||||
[libraryItems],
|
||||
);
|
||||
|
||||
const showBtn = !libraryItems.length && !pendingElements.length;
|
||||
|
||||
const isLibraryEmpty =
|
||||
!pendingElements.length &&
|
||||
!unpublishedItems.length &&
|
||||
!publishedItems.length;
|
||||
|
||||
const [lastSelectedItem, setLastSelectedItem] = useState<
|
||||
LibraryItem["id"] | null
|
||||
>(null);
|
||||
|
||||
const onItemSelectToggle = useCallback(
|
||||
(id: LibraryItem["id"], event: React.MouseEvent) => {
|
||||
const shouldSelect = !selectedItems.includes(id);
|
||||
|
||||
const orderedItems = [...unpublishedItems, ...publishedItems];
|
||||
|
||||
if (shouldSelect) {
|
||||
if (event.shiftKey && lastSelectedItem) {
|
||||
const rangeStart = orderedItems.findIndex(
|
||||
@@ -138,13 +115,10 @@ export default function LibraryMenuItems({
|
||||
}
|
||||
|
||||
const selectedItemsMap = arrayToMap(selectedItems);
|
||||
// Support both top-down and bottom-up selection by using min/max
|
||||
const minRange = Math.min(rangeStart, rangeEnd);
|
||||
const maxRange = Math.max(rangeStart, rangeEnd);
|
||||
const nextSelectedIds = orderedItems.reduce(
|
||||
(acc: LibraryItem["id"][], item, idx) => {
|
||||
if (
|
||||
(idx >= minRange && idx <= maxRange) ||
|
||||
(idx >= rangeStart && idx <= rangeEnd) ||
|
||||
selectedItemsMap.has(item.id)
|
||||
) {
|
||||
acc.push(item.id);
|
||||
@@ -153,6 +127,7 @@ export default function LibraryMenuItems({
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
onSelectItems(nextSelectedIds);
|
||||
} else {
|
||||
onSelectItems([...selectedItems, id]);
|
||||
@@ -172,14 +147,6 @@ export default function LibraryMenuItems({
|
||||
],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// if selection is removed (e.g. via esc), reset last selected item
|
||||
// so that subsequent shift+clicks don't select a large range
|
||||
if (!selectedItems.length) {
|
||||
setLastSelectedItem(null);
|
||||
}
|
||||
}, [selectedItems]);
|
||||
|
||||
const getInsertedElements = useCallback(
|
||||
(id: string) => {
|
||||
let targetElements;
|
||||
@@ -208,17 +175,12 @@ export default function LibraryMenuItems({
|
||||
|
||||
const onItemDrag = useCallback(
|
||||
(id: LibraryItem["id"], event: React.DragEvent) => {
|
||||
// we want to serialize just the ids so the operation is fast and there's
|
||||
// no race condition if people drop the library items on canvas too fast
|
||||
const data: ExcalidrawLibraryIds = {
|
||||
itemIds: selectedItems.includes(id) ? selectedItems : [id],
|
||||
};
|
||||
event.dataTransfer.setData(
|
||||
MIME_TYPES.excalidrawlibIds,
|
||||
JSON.stringify(data),
|
||||
MIME_TYPES.excalidrawlib,
|
||||
serializeLibraryAsJSON(getInsertedElements(id)),
|
||||
);
|
||||
},
|
||||
[selectedItems],
|
||||
[getInsertedElements],
|
||||
);
|
||||
|
||||
const isItemSelected = useCallback(
|
||||
@@ -226,6 +188,7 @@ export default function LibraryMenuItems({
|
||||
if (!id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return selectedItems.includes(id);
|
||||
},
|
||||
[selectedItems],
|
||||
@@ -245,136 +208,10 @@ export default function LibraryMenuItems({
|
||||
);
|
||||
|
||||
const itemsRenderedPerBatch =
|
||||
svgCache.size >=
|
||||
(filteredItems.length ? filteredItems : libraryItems).length
|
||||
svgCache.size >= libraryItems.length
|
||||
? CACHED_ITEMS_RENDERED_PER_BATCH
|
||||
: ITEMS_RENDERED_PER_BATCH;
|
||||
|
||||
const searchInputRef = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => {
|
||||
// focus could be stolen by tab trigger button
|
||||
nextAnimationFrame(() => {
|
||||
searchInputRef.current?.focus();
|
||||
});
|
||||
}, []);
|
||||
|
||||
const JSX_whenNotSearching = !IS_SEARCHING && (
|
||||
<>
|
||||
{!IS_LIBRARY_EMPTY && (
|
||||
<div className="library-menu-items-container__header">
|
||||
{t("labels.personalLib")}
|
||||
</div>
|
||||
)}
|
||||
{!pendingElements.length && !unpublishedItems.length ? (
|
||||
<div className="library-menu-items__no-items">
|
||||
{!publishedItems.length && (
|
||||
<div className="library-menu-items__no-items__label">
|
||||
{t("library.noItems")}
|
||||
</div>
|
||||
)}
|
||||
<div className="library-menu-items__no-items__hint">
|
||||
{publishedItems.length > 0
|
||||
? t("library.hint_emptyPrivateLibrary")
|
||||
: t("library.hint_emptyLibrary")}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<LibraryMenuSectionGrid>
|
||||
{pendingElements.length > 0 && (
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={[{ id: null, elements: pendingElements }]}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onAddToLibraryClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
)}
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={unpublishedItems}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onItemClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
</LibraryMenuSectionGrid>
|
||||
)}
|
||||
|
||||
{publishedItems.length > 0 && (
|
||||
<div
|
||||
className="library-menu-items-container__header"
|
||||
style={{ marginTop: "0.75rem" }}
|
||||
>
|
||||
{t("labels.excalidrawLib")}
|
||||
</div>
|
||||
)}
|
||||
{publishedItems.length > 0 && (
|
||||
<LibraryMenuSectionGrid>
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={publishedItems}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onItemClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
</LibraryMenuSectionGrid>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
const JSX_whenSearching = IS_SEARCHING && (
|
||||
<>
|
||||
<div className="library-menu-items-container__header">
|
||||
{t("library.search.heading")}
|
||||
{!isLoading && (
|
||||
<div
|
||||
className="library-menu-items-container__header__hint"
|
||||
style={{ cursor: "pointer" }}
|
||||
onPointerDown={(e) => e.preventDefault()}
|
||||
onClick={(event) => {
|
||||
setSearchInputValue("");
|
||||
}}
|
||||
>
|
||||
<kbd>esc</kbd> to clear
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{filteredItems.length > 0 ? (
|
||||
<LibraryMenuSectionGrid>
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={filteredItems}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onItemClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
</LibraryMenuSectionGrid>
|
||||
) : (
|
||||
<div className="library-menu-items__no-items">
|
||||
<div className="library-menu-items__no-items__hint">
|
||||
{t("library.search.noResults")}
|
||||
</div>
|
||||
<Button
|
||||
onPointerDown={(e) => e.preventDefault()}
|
||||
onSelect={() => {
|
||||
setSearchInputValue("");
|
||||
}}
|
||||
style={{ width: "auto", marginTop: "1rem" }}
|
||||
>
|
||||
{t("library.search.clearSearch")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
className="library-menu-items-container"
|
||||
@@ -386,58 +223,127 @@ export default function LibraryMenuItems({
|
||||
: { borderBottom: 0 }
|
||||
}
|
||||
>
|
||||
<div className="library-menu-items-header">
|
||||
{!IS_LIBRARY_EMPTY && (
|
||||
<TextField
|
||||
ref={searchInputRef}
|
||||
type="search"
|
||||
className={clsx("library-menu-items-container__search", {
|
||||
hideCancelButton: !device.editor.isMobile,
|
||||
})}
|
||||
placeholder={t("library.search.inputPlaceholder")}
|
||||
value={searchInputValue}
|
||||
onChange={(value) => setSearchInputValue(value)}
|
||||
/>
|
||||
)}
|
||||
{!isLibraryEmpty && (
|
||||
<LibraryDropdownMenu
|
||||
selectedItems={selectedItems}
|
||||
onSelectItems={onSelectItems}
|
||||
className="library-menu-dropdown-container--in-heading"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<Stack.Col
|
||||
className="library-menu-items-container__items"
|
||||
align="start"
|
||||
gap={1}
|
||||
style={{
|
||||
flex: publishedItems.length > 0 ? 1 : "0 1 auto",
|
||||
margin: IS_LIBRARY_EMPTY ? "auto" : 0,
|
||||
marginBottom: 0,
|
||||
}}
|
||||
ref={libraryContainerRef}
|
||||
>
|
||||
{isLoading && (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "var(--container-padding-y)",
|
||||
right: "var(--container-padding-x)",
|
||||
transform: "translateY(50%)",
|
||||
}}
|
||||
>
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
<>
|
||||
{!isLibraryEmpty && (
|
||||
<div className="library-menu-items-container__header">
|
||||
{t("labels.personalLib")}
|
||||
</div>
|
||||
)}
|
||||
{isLoading && (
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: "var(--container-padding-y)",
|
||||
right: "var(--container-padding-x)",
|
||||
transform: "translateY(50%)",
|
||||
}}
|
||||
>
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
{!pendingElements.length && !unpublishedItems.length ? (
|
||||
<div className="library-menu-items__no-items">
|
||||
<div className="library-menu-items__no-items__label">
|
||||
{t("library.noItems")}
|
||||
</div>
|
||||
<div className="library-menu-items__no-items__hint">
|
||||
{publishedItems.length > 0
|
||||
? t("library.hint_emptyPrivateLibrary")
|
||||
: t("library.hint_emptyLibrary")}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<LibraryMenuSectionGrid>
|
||||
{pendingElements.length > 0 && (
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={[{ id: null, elements: pendingElements }]}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onAddToLibraryClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
)}
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={unpublishedItems}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onItemClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
</LibraryMenuSectionGrid>
|
||||
)}
|
||||
</>
|
||||
|
||||
{JSX_whenNotSearching}
|
||||
{JSX_whenSearching}
|
||||
<>
|
||||
{(publishedItems.length > 0 ||
|
||||
pendingElements.length > 0 ||
|
||||
unpublishedItems.length > 0) && (
|
||||
<div className="library-menu-items-container__header library-menu-items-container__header--excal">
|
||||
{t("labels.excalidrawLib")}
|
||||
</div>
|
||||
)}
|
||||
{publishedItems.length > 0 ? (
|
||||
<LibraryMenuSectionGrid>
|
||||
<LibraryMenuSection
|
||||
itemsRenderedPerBatch={itemsRenderedPerBatch}
|
||||
items={publishedItems}
|
||||
onItemSelectToggle={onItemSelectToggle}
|
||||
onItemDrag={onItemDrag}
|
||||
onClick={onItemClick}
|
||||
isItemSelected={isItemSelected}
|
||||
svgCache={svgCache}
|
||||
/>
|
||||
</LibraryMenuSectionGrid>
|
||||
) : unpublishedItems.length > 0 ? (
|
||||
<div
|
||||
style={{
|
||||
margin: "1rem 0",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
width: "100%",
|
||||
fontSize: ".9rem",
|
||||
}}
|
||||
>
|
||||
{t("library.noItems")}
|
||||
</div>
|
||||
) : null}
|
||||
</>
|
||||
|
||||
{IS_LIBRARY_EMPTY && (
|
||||
{showBtn && (
|
||||
<LibraryMenuControlButtons
|
||||
style={{ padding: "16px 0", width: "100%" }}
|
||||
id={id}
|
||||
libraryReturnUrl={libraryReturnUrl}
|
||||
theme={theme}
|
||||
/>
|
||||
>
|
||||
<LibraryDropdownMenu
|
||||
selectedItems={selectedItems}
|
||||
onSelectItems={onSelectItems}
|
||||
/>
|
||||
</LibraryMenuControlButtons>
|
||||
)}
|
||||
</Stack.Col>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { SvgCache } from "../hooks/useLibraryItemSvg";
|
||||
import type { LibraryItem } from "../types";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
type LibraryOrPendingItem = readonly (
|
||||
type LibraryOrPendingItem = (
|
||||
| LibraryItem
|
||||
| /* pending library item */ {
|
||||
id: null;
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
}
|
||||
|
||||
&--hover {
|
||||
background-color: var(--color-surface-mid);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
&:active:not(:has(.library-unit__checkbox:hover)),
|
||||
&--selected {
|
||||
background-color: var(--color-surface-high);
|
||||
border-color: var(--color-primary);
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
&--skeleton {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import clsx from "clsx";
|
||||
import { memo, useRef, useState } from "react";
|
||||
import { memo, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { useLibraryItemSvg } from "../hooks/useLibraryItemSvg";
|
||||
|
||||
@@ -33,7 +33,23 @@ export const LibraryUnit = memo(
|
||||
svgCache: SvgCache;
|
||||
}) => {
|
||||
const ref = useRef<HTMLDivElement | null>(null);
|
||||
const svg = useLibraryItemSvg(id, elements, svgCache, ref);
|
||||
const svg = useLibraryItemSvg(id, elements, svgCache);
|
||||
|
||||
useEffect(() => {
|
||||
const node = ref.current;
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (svg) {
|
||||
node.innerHTML = svg.outerHTML;
|
||||
}
|
||||
|
||||
return () => {
|
||||
node.innerHTML = "";
|
||||
};
|
||||
}, [svg]);
|
||||
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const isMobile = useDevice().editor.isMobile;
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
import React from "react";
|
||||
|
||||
import { showSelectedShapeActions } from "@excalidraw/element";
|
||||
|
||||
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
|
||||
|
||||
import { isHandToolActive } from "../appState";
|
||||
import { useTunnels } from "../context/tunnels";
|
||||
import { t } from "../i18n";
|
||||
import { calculateScrollCenter } from "../scene";
|
||||
import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars";
|
||||
|
||||
import { MobileShapeActions } from "./Actions";
|
||||
import { MobileToolBar } from "./MobileToolBar";
|
||||
import { SelectedShapeActions, ShapesSwitcher } from "./Actions";
|
||||
import { FixedSideContainer } from "./FixedSideContainer";
|
||||
|
||||
import { HandButton } from "./HandButton";
|
||||
import { HintViewer } from "./HintViewer";
|
||||
import { Island } from "./Island";
|
||||
import { LockButton } from "./LockButton";
|
||||
import { PenModeButton } from "./PenModeButton";
|
||||
import { Section } from "./Section";
|
||||
import Stack from "./Stack";
|
||||
|
||||
import type { ActionManager } from "../actions/manager";
|
||||
import type {
|
||||
AppClassProperties,
|
||||
AppProps,
|
||||
AppState,
|
||||
Device,
|
||||
ExcalidrawProps,
|
||||
UIAppState,
|
||||
} from "../types";
|
||||
import type { JSX } from "react";
|
||||
@@ -29,6 +38,7 @@ type MobileMenuProps = {
|
||||
renderImageExportDialog: () => React.ReactNode;
|
||||
setAppState: React.Component<any, AppState>["setState"];
|
||||
elements: readonly NonDeletedExcalidrawElement[];
|
||||
onLockToggle: () => void;
|
||||
onHandToolToggle: () => void;
|
||||
onPenModeToggle: AppClassProperties["togglePenMode"];
|
||||
|
||||
@@ -36,11 +46,9 @@ type MobileMenuProps = {
|
||||
isMobile: boolean,
|
||||
appState: UIAppState,
|
||||
) => JSX.Element | null;
|
||||
renderTopLeftUI?: (
|
||||
isMobile: boolean,
|
||||
appState: UIAppState,
|
||||
) => JSX.Element | null;
|
||||
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
|
||||
renderSidebars: () => JSX.Element | null;
|
||||
device: Device;
|
||||
renderWelcomeScreen: boolean;
|
||||
UIOptions: AppProps["UIOptions"];
|
||||
app: AppClassProperties;
|
||||
@@ -51,10 +59,14 @@ export const MobileMenu = ({
|
||||
elements,
|
||||
actionManager,
|
||||
setAppState,
|
||||
onLockToggle,
|
||||
onHandToolToggle,
|
||||
renderTopLeftUI,
|
||||
onPenModeToggle,
|
||||
|
||||
renderTopRightUI,
|
||||
renderCustomStats,
|
||||
renderSidebars,
|
||||
device,
|
||||
renderWelcomeScreen,
|
||||
UIOptions,
|
||||
app,
|
||||
@@ -64,98 +76,141 @@ export const MobileMenu = ({
|
||||
MainMenuTunnel,
|
||||
DefaultSidebarTriggerTunnel,
|
||||
} = useTunnels();
|
||||
const renderAppTopBar = () => {
|
||||
const topRightUI = renderTopRightUI?.(true, appState) ?? (
|
||||
<DefaultSidebarTriggerTunnel.Out />
|
||||
);
|
||||
|
||||
const topLeftUI = (
|
||||
<div className="excalidraw-ui-top-left">
|
||||
{renderTopLeftUI?.(true, appState)}
|
||||
<MainMenuTunnel.Out />
|
||||
</div>
|
||||
const renderToolbar = () => {
|
||||
return (
|
||||
<FixedSideContainer side="top" className="App-top-bar">
|
||||
{renderWelcomeScreen && <WelcomeScreenCenterTunnel.Out />}
|
||||
<Section heading="shapes">
|
||||
{(heading: React.ReactNode) => (
|
||||
<Stack.Col gap={4} align="center">
|
||||
<Stack.Row gap={1} className="App-toolbar-container">
|
||||
<Island padding={1} className="App-toolbar App-toolbar--mobile">
|
||||
{heading}
|
||||
<Stack.Row gap={1}>
|
||||
<ShapesSwitcher
|
||||
appState={appState}
|
||||
activeTool={appState.activeTool}
|
||||
UIOptions={UIOptions}
|
||||
app={app}
|
||||
/>
|
||||
</Stack.Row>
|
||||
</Island>
|
||||
{renderTopRightUI && renderTopRightUI(true, appState)}
|
||||
<div className="mobile-misc-tools-container">
|
||||
{!appState.viewModeEnabled &&
|
||||
appState.openDialog?.name !== "elementLinkSelector" && (
|
||||
<DefaultSidebarTriggerTunnel.Out />
|
||||
)}
|
||||
<PenModeButton
|
||||
checked={appState.penMode}
|
||||
onChange={() => onPenModeToggle(null)}
|
||||
title={t("toolBar.penMode")}
|
||||
isMobile
|
||||
penDetected={appState.penDetected}
|
||||
/>
|
||||
<LockButton
|
||||
checked={appState.activeTool.locked}
|
||||
onChange={onLockToggle}
|
||||
title={t("toolBar.lock")}
|
||||
isMobile
|
||||
/>
|
||||
<HandButton
|
||||
checked={isHandToolActive(appState)}
|
||||
onChange={() => onHandToolToggle()}
|
||||
title={t("toolBar.hand")}
|
||||
isMobile
|
||||
/>
|
||||
</div>
|
||||
</Stack.Row>
|
||||
</Stack.Col>
|
||||
)}
|
||||
</Section>
|
||||
<HintViewer
|
||||
appState={appState}
|
||||
isMobile={true}
|
||||
device={device}
|
||||
app={app}
|
||||
/>
|
||||
</FixedSideContainer>
|
||||
);
|
||||
};
|
||||
|
||||
const renderAppToolbar = () => {
|
||||
if (
|
||||
appState.viewModeEnabled ||
|
||||
appState.openDialog?.name === "elementLinkSelector"
|
||||
) {
|
||||
return <div className="App-toolbar-content">{topLeftUI}</div>;
|
||||
return (
|
||||
<div className="App-toolbar-content">
|
||||
<MainMenuTunnel.Out />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="App-toolbar-content"
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
}}
|
||||
>
|
||||
{topLeftUI}
|
||||
{topRightUI}
|
||||
<div className="App-toolbar-content">
|
||||
<MainMenuTunnel.Out />
|
||||
{actionManager.renderAction("toggleEditMenu")}
|
||||
{actionManager.renderAction(
|
||||
appState.multiElement ? "finalize" : "duplicateSelection",
|
||||
)}
|
||||
{actionManager.renderAction("deleteSelectedElements")}
|
||||
<div>
|
||||
{actionManager.renderAction("undo")}
|
||||
{actionManager.renderAction("redo")}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderToolbar = () => {
|
||||
return (
|
||||
<MobileToolBar
|
||||
app={app}
|
||||
onHandToolToggle={onHandToolToggle}
|
||||
setAppState={setAppState}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{renderSidebars()}
|
||||
{/* welcome screen, bottom bar, and top bar all have the same z-index */}
|
||||
{/* ordered in this reverse order so that top bar is on top */}
|
||||
<div className="App-welcome-screen">
|
||||
{renderWelcomeScreen && <WelcomeScreenCenterTunnel.Out />}
|
||||
</div>
|
||||
|
||||
{!appState.viewModeEnabled &&
|
||||
appState.openDialog?.name !== "elementLinkSelector" &&
|
||||
renderToolbar()}
|
||||
<div
|
||||
className="App-bottom-bar"
|
||||
style={{
|
||||
marginBottom: SCROLLBAR_WIDTH + SCROLLBAR_MARGIN,
|
||||
marginBottom: SCROLLBAR_WIDTH + SCROLLBAR_MARGIN * 2,
|
||||
marginLeft: SCROLLBAR_WIDTH + SCROLLBAR_MARGIN * 2,
|
||||
marginRight: SCROLLBAR_WIDTH + SCROLLBAR_MARGIN * 2,
|
||||
}}
|
||||
>
|
||||
<MobileShapeActions
|
||||
appState={appState}
|
||||
elementsMap={app.scene.getNonDeletedElementsMap()}
|
||||
renderAction={actionManager.renderAction}
|
||||
app={app}
|
||||
setAppState={setAppState}
|
||||
/>
|
||||
|
||||
<Island className="App-toolbar">
|
||||
{!appState.viewModeEnabled &&
|
||||
appState.openDialog?.name !== "elementLinkSelector" &&
|
||||
renderToolbar()}
|
||||
{appState.scrolledOutside &&
|
||||
!appState.openMenu &&
|
||||
!appState.openSidebar && (
|
||||
<button
|
||||
type="button"
|
||||
className="scroll-back-to-content"
|
||||
onClick={() => {
|
||||
setAppState((appState) => ({
|
||||
...calculateScrollCenter(elements, appState),
|
||||
}));
|
||||
}}
|
||||
>
|
||||
{t("buttons.scrollBackToContent")}
|
||||
</button>
|
||||
)}
|
||||
<Island padding={0}>
|
||||
{appState.openMenu === "shape" &&
|
||||
!appState.viewModeEnabled &&
|
||||
appState.openDialog?.name !== "elementLinkSelector" &&
|
||||
showSelectedShapeActions(appState, elements) ? (
|
||||
<Section className="App-mobile-menu" heading="selectedShapeActions">
|
||||
<SelectedShapeActions
|
||||
appState={appState}
|
||||
elementsMap={app.scene.getNonDeletedElementsMap()}
|
||||
renderAction={actionManager.renderAction}
|
||||
app={app}
|
||||
/>
|
||||
</Section>
|
||||
) : null}
|
||||
<footer className="App-toolbar">
|
||||
{renderAppToolbar()}
|
||||
{appState.scrolledOutside &&
|
||||
!appState.openMenu &&
|
||||
!appState.openSidebar && (
|
||||
<button
|
||||
type="button"
|
||||
className="scroll-back-to-content"
|
||||
onClick={() => {
|
||||
setAppState((appState) => ({
|
||||
...calculateScrollCenter(elements, appState),
|
||||
}));
|
||||
}}
|
||||
>
|
||||
{t("buttons.scrollBackToContent")}
|
||||
</button>
|
||||
)}
|
||||
</footer>
|
||||
</Island>
|
||||
</div>
|
||||
|
||||
<FixedSideContainer side="top" className="App-top-bar">
|
||||
{renderAppTopBar()}
|
||||
</FixedSideContainer>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
@import "open-color/open-color.scss";
|
||||
@import "../css/variables.module.scss";
|
||||
|
||||
.excalidraw {
|
||||
.mobile-toolbar {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
padding: 0px;
|
||||
gap: 4px;
|
||||
border-radius: var(--space-factor);
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
-ms-overflow-style: none;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.mobile-toolbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-toolbar .ToolIcon {
|
||||
min-width: 2rem;
|
||||
min-height: 2rem;
|
||||
border-radius: 4px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
|
||||
.ToolIcon__icon {
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
|
||||
&:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: var(
|
||||
--color-surface-primary-container,
|
||||
var(--island-bg-color)
|
||||
);
|
||||
border-color: var(--button-active-border, var(--color-primary-darkest));
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
.mobile-toolbar .App-toolbar__extra-tools-dropdown {
|
||||
min-width: 160px;
|
||||
z-index: var(--zIndex-layerUI);
|
||||
}
|
||||
|
||||
.mobile-toolbar-separator {
|
||||
width: 1px;
|
||||
height: 24px;
|
||||
background: var(--default-border-color);
|
||||
margin: 0 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.mobile-toolbar-undo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.mobile-toolbar-undo .ToolIcon {
|
||||
min-width: 32px;
|
||||
min-height: 32px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
}
|
||||
@@ -1,474 +0,0 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import clsx from "clsx";
|
||||
|
||||
import { KEYS, capitalizeString } from "@excalidraw/common";
|
||||
|
||||
import { trackEvent } from "../analytics";
|
||||
|
||||
import { t } from "../i18n";
|
||||
|
||||
import { isHandToolActive } from "../appState";
|
||||
|
||||
import { useTunnels } from "../context/tunnels";
|
||||
|
||||
import { HandButton } from "./HandButton";
|
||||
import { ToolButton } from "./ToolButton";
|
||||
import DropdownMenu from "./dropdownMenu/DropdownMenu";
|
||||
import { ToolPopover } from "./ToolPopover";
|
||||
|
||||
import {
|
||||
SelectionIcon,
|
||||
FreedrawIcon,
|
||||
EraserIcon,
|
||||
RectangleIcon,
|
||||
ArrowIcon,
|
||||
extraToolsIcon,
|
||||
DiamondIcon,
|
||||
EllipseIcon,
|
||||
LineIcon,
|
||||
TextIcon,
|
||||
ImageIcon,
|
||||
frameToolIcon,
|
||||
EmbedIcon,
|
||||
laserPointerToolIcon,
|
||||
LassoIcon,
|
||||
mermaidLogoIcon,
|
||||
MagicIcon,
|
||||
} from "./icons";
|
||||
|
||||
import "./ToolIcon.scss";
|
||||
import "./MobileToolBar.scss";
|
||||
|
||||
import type { AppClassProperties, ToolType, UIAppState } from "../types";
|
||||
|
||||
const SHAPE_TOOLS = [
|
||||
{
|
||||
type: "rectangle",
|
||||
icon: RectangleIcon,
|
||||
title: capitalizeString(t("toolBar.rectangle")),
|
||||
},
|
||||
{
|
||||
type: "diamond",
|
||||
icon: DiamondIcon,
|
||||
title: capitalizeString(t("toolBar.diamond")),
|
||||
},
|
||||
{
|
||||
type: "ellipse",
|
||||
icon: EllipseIcon,
|
||||
title: capitalizeString(t("toolBar.ellipse")),
|
||||
},
|
||||
] as const;
|
||||
|
||||
const SELECTION_TOOLS = [
|
||||
{
|
||||
type: "selection",
|
||||
icon: SelectionIcon,
|
||||
title: capitalizeString(t("toolBar.selection")),
|
||||
},
|
||||
{
|
||||
type: "lasso",
|
||||
icon: LassoIcon,
|
||||
title: capitalizeString(t("toolBar.lasso")),
|
||||
},
|
||||
] as const;
|
||||
|
||||
const LINEAR_ELEMENT_TOOLS = [
|
||||
{
|
||||
type: "arrow",
|
||||
icon: ArrowIcon,
|
||||
title: capitalizeString(t("toolBar.arrow")),
|
||||
},
|
||||
{ type: "line", icon: LineIcon, title: capitalizeString(t("toolBar.line")) },
|
||||
] as const;
|
||||
|
||||
type MobileToolBarProps = {
|
||||
app: AppClassProperties;
|
||||
onHandToolToggle: () => void;
|
||||
setAppState: React.Component<any, UIAppState>["setState"];
|
||||
};
|
||||
|
||||
export const MobileToolBar = ({
|
||||
app,
|
||||
onHandToolToggle,
|
||||
setAppState,
|
||||
}: MobileToolBarProps) => {
|
||||
const activeTool = app.state.activeTool;
|
||||
const [isOtherShapesMenuOpen, setIsOtherShapesMenuOpen] = useState(false);
|
||||
const [lastActiveGenericShape, setLastActiveGenericShape] = useState<
|
||||
"rectangle" | "diamond" | "ellipse"
|
||||
>("rectangle");
|
||||
const [lastActiveLinearElement, setLastActiveLinearElement] = useState<
|
||||
"arrow" | "line"
|
||||
>("arrow");
|
||||
|
||||
const toolbarRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// keep lastActiveGenericShape in sync with active tool if user switches via other UI
|
||||
useEffect(() => {
|
||||
if (
|
||||
activeTool.type === "rectangle" ||
|
||||
activeTool.type === "diamond" ||
|
||||
activeTool.type === "ellipse"
|
||||
) {
|
||||
setLastActiveGenericShape(activeTool.type);
|
||||
}
|
||||
}, [activeTool.type]);
|
||||
|
||||
// keep lastActiveLinearElement in sync with active tool if user switches via other UI
|
||||
useEffect(() => {
|
||||
if (activeTool.type === "arrow" || activeTool.type === "line") {
|
||||
setLastActiveLinearElement(activeTool.type);
|
||||
}
|
||||
}, [activeTool.type]);
|
||||
|
||||
const frameToolSelected = activeTool.type === "frame";
|
||||
const laserToolSelected = activeTool.type === "laser";
|
||||
const embeddableToolSelected = activeTool.type === "embeddable";
|
||||
|
||||
const { TTDDialogTriggerTunnel } = useTunnels();
|
||||
|
||||
const handleToolChange = (toolType: string, pointerType?: string) => {
|
||||
if (app.state.activeTool.type !== toolType) {
|
||||
trackEvent("toolbar", toolType, "ui");
|
||||
}
|
||||
|
||||
if (toolType === "selection") {
|
||||
if (app.state.activeTool.type === "selection") {
|
||||
// Toggle selection tool behavior if needed
|
||||
} else {
|
||||
app.setActiveTool({ type: "selection" });
|
||||
}
|
||||
} else {
|
||||
app.setActiveTool({ type: toolType as ToolType });
|
||||
}
|
||||
};
|
||||
|
||||
const toolbarWidth =
|
||||
toolbarRef.current?.getBoundingClientRect()?.width ?? 0 - 8;
|
||||
const WIDTH = 36;
|
||||
const GAP = 4;
|
||||
|
||||
// hand, selection, freedraw, eraser, rectangle, arrow, others
|
||||
const MIN_TOOLS = 7;
|
||||
const MIN_WIDTH = MIN_TOOLS * WIDTH + (MIN_TOOLS - 1) * GAP;
|
||||
const ADDITIONAL_WIDTH = WIDTH + GAP;
|
||||
|
||||
const showTextToolOutside = toolbarWidth >= MIN_WIDTH + 1 * ADDITIONAL_WIDTH;
|
||||
const showImageToolOutside = toolbarWidth >= MIN_WIDTH + 2 * ADDITIONAL_WIDTH;
|
||||
const showFrameToolOutside = toolbarWidth >= MIN_WIDTH + 3 * ADDITIONAL_WIDTH;
|
||||
|
||||
const extraTools = [
|
||||
"text",
|
||||
"frame",
|
||||
"embeddable",
|
||||
"laser",
|
||||
"magicframe",
|
||||
].filter((tool) => {
|
||||
if (showImageToolOutside && tool === "image") {
|
||||
return false;
|
||||
}
|
||||
if (showFrameToolOutside && tool === "frame") {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const extraToolSelected = extraTools.includes(activeTool.type);
|
||||
const extraIcon = extraToolSelected
|
||||
? activeTool.type === "frame"
|
||||
? frameToolIcon
|
||||
: activeTool.type === "embeddable"
|
||||
? EmbedIcon
|
||||
: activeTool.type === "laser"
|
||||
? laserPointerToolIcon
|
||||
: activeTool.type === "text"
|
||||
? TextIcon
|
||||
: activeTool.type === "magicframe"
|
||||
? MagicIcon
|
||||
: extraToolsIcon
|
||||
: extraToolsIcon;
|
||||
|
||||
return (
|
||||
<div className="mobile-toolbar" ref={toolbarRef}>
|
||||
{/* Hand Tool */}
|
||||
<HandButton
|
||||
checked={isHandToolActive(app.state)}
|
||||
onChange={onHandToolToggle}
|
||||
title={t("toolBar.hand")}
|
||||
isMobile
|
||||
/>
|
||||
|
||||
{/* Selection Tool */}
|
||||
<ToolPopover
|
||||
app={app}
|
||||
options={SELECTION_TOOLS}
|
||||
activeTool={activeTool}
|
||||
defaultOption={app.state.preferredSelectionTool.type}
|
||||
namePrefix="selectionType"
|
||||
title={capitalizeString(t("toolBar.selection"))}
|
||||
data-testid="toolbar-selection"
|
||||
onToolChange={(type: string) => {
|
||||
if (type === "selection" || type === "lasso") {
|
||||
app.setActiveTool({ type });
|
||||
setAppState({
|
||||
preferredSelectionTool: { type, initialized: true },
|
||||
});
|
||||
}
|
||||
}}
|
||||
displayedOption={
|
||||
SELECTION_TOOLS.find(
|
||||
(tool) => tool.type === app.state.preferredSelectionTool.type,
|
||||
) || SELECTION_TOOLS[0]
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Free Draw */}
|
||||
<ToolButton
|
||||
className={clsx({
|
||||
active: activeTool.type === "freedraw",
|
||||
})}
|
||||
type="radio"
|
||||
icon={FreedrawIcon}
|
||||
checked={activeTool.type === "freedraw"}
|
||||
name="editor-current-shape"
|
||||
title={`${capitalizeString(t("toolBar.freedraw"))}`}
|
||||
aria-label={capitalizeString(t("toolBar.freedraw"))}
|
||||
data-testid="toolbar-freedraw"
|
||||
onChange={() => handleToolChange("freedraw")}
|
||||
/>
|
||||
|
||||
{/* Eraser */}
|
||||
<ToolButton
|
||||
className={clsx({
|
||||
active: activeTool.type === "eraser",
|
||||
})}
|
||||
type="radio"
|
||||
icon={EraserIcon}
|
||||
checked={activeTool.type === "eraser"}
|
||||
name="editor-current-shape"
|
||||
title={`${capitalizeString(t("toolBar.eraser"))}`}
|
||||
aria-label={capitalizeString(t("toolBar.eraser"))}
|
||||
data-testid="toolbar-eraser"
|
||||
onChange={() => handleToolChange("eraser")}
|
||||
/>
|
||||
|
||||
{/* Rectangle */}
|
||||
<ToolPopover
|
||||
app={app}
|
||||
options={SHAPE_TOOLS}
|
||||
activeTool={activeTool}
|
||||
defaultOption={lastActiveGenericShape}
|
||||
namePrefix="shapeType"
|
||||
title={capitalizeString(
|
||||
t(
|
||||
lastActiveGenericShape === "rectangle"
|
||||
? "toolBar.rectangle"
|
||||
: lastActiveGenericShape === "diamond"
|
||||
? "toolBar.diamond"
|
||||
: lastActiveGenericShape === "ellipse"
|
||||
? "toolBar.ellipse"
|
||||
: "toolBar.rectangle",
|
||||
),
|
||||
)}
|
||||
data-testid="toolbar-rectangle"
|
||||
onToolChange={(type: string) => {
|
||||
if (
|
||||
type === "rectangle" ||
|
||||
type === "diamond" ||
|
||||
type === "ellipse"
|
||||
) {
|
||||
setLastActiveGenericShape(type);
|
||||
app.setActiveTool({ type });
|
||||
}
|
||||
}}
|
||||
displayedOption={
|
||||
SHAPE_TOOLS.find((tool) => tool.type === lastActiveGenericShape) ||
|
||||
SHAPE_TOOLS[0]
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Arrow/Line */}
|
||||
<ToolPopover
|
||||
app={app}
|
||||
options={LINEAR_ELEMENT_TOOLS}
|
||||
activeTool={activeTool}
|
||||
defaultOption={lastActiveLinearElement}
|
||||
namePrefix="linearElementType"
|
||||
title={capitalizeString(
|
||||
t(
|
||||
lastActiveLinearElement === "arrow"
|
||||
? "toolBar.arrow"
|
||||
: "toolBar.line",
|
||||
),
|
||||
)}
|
||||
data-testid="toolbar-arrow"
|
||||
fillable={true}
|
||||
onToolChange={(type: string) => {
|
||||
if (type === "arrow" || type === "line") {
|
||||
setLastActiveLinearElement(type);
|
||||
app.setActiveTool({ type });
|
||||
}
|
||||
}}
|
||||
displayedOption={
|
||||
LINEAR_ELEMENT_TOOLS.find(
|
||||
(tool) => tool.type === lastActiveLinearElement,
|
||||
) || LINEAR_ELEMENT_TOOLS[0]
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Text Tool */}
|
||||
{showTextToolOutside && (
|
||||
<ToolButton
|
||||
className={clsx({
|
||||
active: activeTool.type === "text",
|
||||
})}
|
||||
type="radio"
|
||||
icon={TextIcon}
|
||||
checked={activeTool.type === "text"}
|
||||
name="editor-current-shape"
|
||||
title={`${capitalizeString(t("toolBar.text"))}`}
|
||||
aria-label={capitalizeString(t("toolBar.text"))}
|
||||
data-testid="toolbar-text"
|
||||
onChange={() => handleToolChange("text")}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Image */}
|
||||
{showImageToolOutside && (
|
||||
<ToolButton
|
||||
className={clsx({
|
||||
active: activeTool.type === "image",
|
||||
})}
|
||||
type="radio"
|
||||
icon={ImageIcon}
|
||||
checked={activeTool.type === "image"}
|
||||
name="editor-current-shape"
|
||||
title={`${capitalizeString(t("toolBar.image"))}`}
|
||||
aria-label={capitalizeString(t("toolBar.image"))}
|
||||
data-testid="toolbar-image"
|
||||
onChange={() => handleToolChange("image")}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Frame Tool */}
|
||||
{showFrameToolOutside && (
|
||||
<ToolButton
|
||||
className={clsx({ active: frameToolSelected })}
|
||||
type="radio"
|
||||
icon={frameToolIcon}
|
||||
checked={frameToolSelected}
|
||||
name="editor-current-shape"
|
||||
title={`${capitalizeString(t("toolBar.frame"))}`}
|
||||
aria-label={capitalizeString(t("toolBar.frame"))}
|
||||
data-testid="toolbar-frame"
|
||||
onChange={() => handleToolChange("frame")}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Other Shapes */}
|
||||
<DropdownMenu open={isOtherShapesMenuOpen} placement="top">
|
||||
<DropdownMenu.Trigger
|
||||
className={clsx(
|
||||
"App-toolbar__extra-tools-trigger App-toolbar__extra-tools-trigger--mobile",
|
||||
{
|
||||
"App-toolbar__extra-tools-trigger--selected":
|
||||
extraToolSelected || isOtherShapesMenuOpen,
|
||||
},
|
||||
)}
|
||||
onToggle={() => {
|
||||
setIsOtherShapesMenuOpen(!isOtherShapesMenuOpen);
|
||||
setAppState({ openMenu: null, openPopup: null });
|
||||
}}
|
||||
title={t("toolBar.extraTools")}
|
||||
style={{
|
||||
width: WIDTH,
|
||||
height: WIDTH,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{extraIcon}
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Content
|
||||
onClickOutside={() => setIsOtherShapesMenuOpen(false)}
|
||||
onSelect={() => setIsOtherShapesMenuOpen(false)}
|
||||
className="App-toolbar__extra-tools-dropdown"
|
||||
>
|
||||
{!showTextToolOutside && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setActiveTool({ type: "text" })}
|
||||
icon={TextIcon}
|
||||
shortcut={KEYS.T.toLocaleUpperCase()}
|
||||
data-testid="toolbar-text"
|
||||
selected={activeTool.type === "text"}
|
||||
>
|
||||
{t("toolBar.text")}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
|
||||
{!showImageToolOutside && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setActiveTool({ type: "image" })}
|
||||
icon={ImageIcon}
|
||||
data-testid="toolbar-image"
|
||||
selected={activeTool.type === "image"}
|
||||
>
|
||||
{t("toolBar.image")}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
{!showFrameToolOutside && (
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setActiveTool({ type: "frame" })}
|
||||
icon={frameToolIcon}
|
||||
shortcut={KEYS.F.toLocaleUpperCase()}
|
||||
data-testid="toolbar-frame"
|
||||
selected={frameToolSelected}
|
||||
>
|
||||
{t("toolBar.frame")}
|
||||
</DropdownMenu.Item>
|
||||
)}
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setActiveTool({ type: "embeddable" })}
|
||||
icon={EmbedIcon}
|
||||
data-testid="toolbar-embeddable"
|
||||
selected={embeddableToolSelected}
|
||||
>
|
||||
{t("toolBar.embeddable")}
|
||||
</DropdownMenu.Item>
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setActiveTool({ type: "laser" })}
|
||||
icon={laserPointerToolIcon}
|
||||
data-testid="toolbar-laser"
|
||||
selected={laserToolSelected}
|
||||
shortcut={KEYS.K.toLocaleUpperCase()}
|
||||
>
|
||||
{t("toolBar.laser")}
|
||||
</DropdownMenu.Item>
|
||||
<div style={{ margin: "6px 0", fontSize: 14, fontWeight: 600 }}>
|
||||
Generate
|
||||
</div>
|
||||
{app.props.aiEnabled !== false && <TTDDialogTriggerTunnel.Out />}
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.setOpenDialog({ name: "ttd", tab: "mermaid" })}
|
||||
icon={mermaidLogoIcon}
|
||||
data-testid="toolbar-embeddable"
|
||||
>
|
||||
{t("toolBar.mermaidToExcalidraw")}
|
||||
</DropdownMenu.Item>
|
||||
{app.props.aiEnabled !== false && app.plugins.diagramToCode && (
|
||||
<>
|
||||
<DropdownMenu.Item
|
||||
onSelect={() => app.onMagicframeToolSelect()}
|
||||
icon={MagicIcon}
|
||||
data-testid="toolbar-magicframe"
|
||||
>
|
||||
{t("toolBar.magicframe")}
|
||||
<DropdownMenu.Item.Badge>AI</DropdownMenu.Item.Badge>
|
||||
</DropdownMenu.Item>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -3,8 +3,6 @@ import { unstable_batchedUpdates } from "react-dom";
|
||||
|
||||
import { KEYS, queryFocusableElements } from "@excalidraw/common";
|
||||
|
||||
import clsx from "clsx";
|
||||
|
||||
import "./Popover.scss";
|
||||
|
||||
type Props = {
|
||||
@@ -17,7 +15,6 @@ type Props = {
|
||||
offsetTop?: number;
|
||||
viewportWidth?: number;
|
||||
viewportHeight?: number;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
export const Popover = ({
|
||||
@@ -30,7 +27,6 @@ export const Popover = ({
|
||||
offsetTop = 0,
|
||||
viewportWidth = window.innerWidth,
|
||||
viewportHeight = window.innerHeight,
|
||||
className,
|
||||
}: Props) => {
|
||||
const popoverRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
@@ -150,7 +146,7 @@ export const Popover = ({
|
||||
}, [onCloseRequest]);
|
||||
|
||||
return (
|
||||
<div className={clsx("popover", className)} ref={popoverRef} tabIndex={-1}>
|
||||
<div className="popover" ref={popoverRef} tabIndex={-1}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -17,7 +17,6 @@ interface PropertiesPopoverProps {
|
||||
onPointerLeave?: React.PointerEventHandler<HTMLDivElement>;
|
||||
onFocusOutside?: Popover.PopoverContentProps["onFocusOutside"];
|
||||
onPointerDownOutside?: Popover.PopoverContentProps["onPointerDownOutside"];
|
||||
preventAutoFocusOnTouch?: boolean;
|
||||
}
|
||||
|
||||
export const PropertiesPopover = React.forwardRef<
|
||||
@@ -35,13 +34,10 @@ export const PropertiesPopover = React.forwardRef<
|
||||
onFocusOutside,
|
||||
onPointerLeave,
|
||||
onPointerDownOutside,
|
||||
preventAutoFocusOnTouch = false,
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const device = useDevice();
|
||||
const isMobilePortrait =
|
||||
device.editor.isMobile && !device.viewport.isLandscape;
|
||||
|
||||
return (
|
||||
<Popover.Portal container={container}>
|
||||
@@ -49,25 +45,25 @@ export const PropertiesPopover = React.forwardRef<
|
||||
ref={ref}
|
||||
className={clsx("focus-visible-none", className)}
|
||||
data-prevent-outside-click
|
||||
side={isMobilePortrait ? "bottom" : "right"}
|
||||
align={isMobilePortrait ? "center" : "start"}
|
||||
side={
|
||||
device.editor.isMobile && !device.viewport.isLandscape
|
||||
? "bottom"
|
||||
: "right"
|
||||
}
|
||||
align={
|
||||
device.editor.isMobile && !device.viewport.isLandscape
|
||||
? "center"
|
||||
: "start"
|
||||
}
|
||||
alignOffset={-16}
|
||||
sideOffset={20}
|
||||
collisionBoundary={container ?? undefined}
|
||||
style={{
|
||||
zIndex: "var(--zIndex-ui-styles-popup)",
|
||||
marginLeft: device.editor.isMobile ? "0.5rem" : undefined,
|
||||
zIndex: "var(--zIndex-popup)",
|
||||
}}
|
||||
onPointerLeave={onPointerLeave}
|
||||
onKeyDown={onKeyDown}
|
||||
onFocusOutside={onFocusOutside}
|
||||
onPointerDownOutside={onPointerDownOutside}
|
||||
onOpenAutoFocus={(e) => {
|
||||
// prevent auto-focus on touch devices to avoid keyboard popup
|
||||
if (preventAutoFocusOnTouch && device.isTouchScreen) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}}
|
||||
onCloseAutoFocus={(e) => {
|
||||
e.stopPropagation();
|
||||
// prevents focusing the trigger
|
||||
|
||||
@@ -518,7 +518,7 @@ const PublishLibrary = ({
|
||||
</div>
|
||||
<div className="publish-library__buttons">
|
||||
<DialogActionButton
|
||||
label={t("buttons.saveLibNames")}
|
||||
label={t("buttons.cancel")}
|
||||
onClick={onDialogClose}
|
||||
data-testid="cancel-clear-canvas-button"
|
||||
/>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user